OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
23 #include "base/time.h" | 23 #include "base/time.h" |
| 24 #include "base/tracked_objects.h" |
24 #include "chrome/browser/chromeos/gdata/file_write_helper.h" | 25 #include "chrome/browser/chromeos/gdata/file_write_helper.h" |
25 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 26 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
26 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | 27 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
27 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
28 #include "chrome/browser/chromeos/login/user.h" | 29 #include "chrome/browser/chromeos/login/user.h" |
29 #include "chrome/browser/chromeos/login/user_manager.h" | 30 #include "chrome/browser/chromeos/login/user_manager.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_finder.h" | 34 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 FilePath remote_path(ExtractGDataPath(path)); | 598 FilePath remote_path(ExtractGDataPath(path)); |
598 file_write_helper->PrepareWritableFileAndRun(remote_path, callback); | 599 file_write_helper->PrepareWritableFileAndRun(remote_path, callback); |
599 } else { | 600 } else { |
600 if (!callback.is_null()) { | 601 if (!callback.is_null()) { |
601 content::BrowserThread::GetBlockingPool()->PostTask( | 602 content::BrowserThread::GetBlockingPool()->PostTask( |
602 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, path)); | 603 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, path)); |
603 } | 604 } |
604 } | 605 } |
605 } | 606 } |
606 | 607 |
| 608 GDataFileError GDataToGDataFileError(GDataErrorCode status) { |
| 609 switch (status) { |
| 610 case HTTP_SUCCESS: |
| 611 case HTTP_CREATED: |
| 612 return GDATA_FILE_OK; |
| 613 case HTTP_UNAUTHORIZED: |
| 614 case HTTP_FORBIDDEN: |
| 615 return GDATA_FILE_ERROR_ACCESS_DENIED; |
| 616 case HTTP_NOT_FOUND: |
| 617 return GDATA_FILE_ERROR_NOT_FOUND; |
| 618 case GDATA_PARSE_ERROR: |
| 619 case GDATA_FILE_ERROR: |
| 620 return GDATA_FILE_ERROR_ABORT; |
| 621 case GDATA_NO_CONNECTION: |
| 622 return GDATA_FILE_ERROR_NO_CONNECTION; |
| 623 default: |
| 624 return GDATA_FILE_ERROR_FAILED; |
| 625 } |
| 626 } |
| 627 |
| 628 void PostBlockingPoolSequencedTask( |
| 629 const tracked_objects::Location& from_here, |
| 630 base::SequencedTaskRunner* blocking_task_runner, |
| 631 const base::Closure& task) { |
| 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 633 |
| 634 const bool posted = blocking_task_runner->PostTask(from_here, task); |
| 635 DCHECK(posted); |
| 636 } |
| 637 |
| 638 void PostBlockingPoolSequencedTaskAndReply( |
| 639 const tracked_objects::Location& from_here, |
| 640 base::SequencedTaskRunner* blocking_task_runner, |
| 641 const base::Closure& request_task, |
| 642 const base::Closure& reply_task) { |
| 643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 644 |
| 645 const bool posted = blocking_task_runner->PostTaskAndReply( |
| 646 from_here, request_task, reply_task); |
| 647 DCHECK(posted); |
| 648 } |
| 649 |
607 } // namespace util | 650 } // namespace util |
608 } // namespace gdata | 651 } // namespace gdata |
OLD | NEW |