| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_file_system/drive_backend_v1/api_util.h" | 5 #include "chrome/browser/sync_file_system/drive_backend_v1/api_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/drive/drive_api_service.h" | 18 #include "chrome/browser/drive/drive_api_service.h" |
| 19 #include "chrome/browser/drive/drive_api_util.h" | 19 #include "chrome/browser/drive/drive_api_util.h" |
| 20 #include "chrome/browser/drive/drive_uploader.h" | 20 #include "chrome/browser/drive/drive_uploader.h" |
| 21 #include "chrome/browser/drive/gdata_wapi_service.h" | 21 #include "chrome/browser/drive/gdata_wapi_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 23 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 25 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" |
| 25 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.
h" | 26 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.
h" |
| 26 #include "chrome/browser/sync_file_system/logger.h" | 27 #include "chrome/browser/sync_file_system/logger.h" |
| 27 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 28 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
| 30 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 31 #include "google_apis/drive/drive_api_parser.h" | 32 #include "google_apis/drive/drive_api_parser.h" |
| 32 #include "google_apis/drive/drive_api_url_generator.h" | 33 #include "google_apis/drive/drive_api_url_generator.h" |
| 33 #include "google_apis/drive/gdata_wapi_url_generator.h" | 34 #include "google_apis/drive/gdata_wapi_url_generator.h" |
| 34 | 35 |
| 35 namespace sync_file_system { | 36 namespace sync_file_system { |
| 36 namespace drive_backend { | 37 namespace drive_backend { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 enum ParentType { | 41 enum ParentType { |
| 41 PARENT_TYPE_ROOT_OR_EMPTY, | 42 PARENT_TYPE_ROOT_OR_EMPTY, |
| 42 PARENT_TYPE_DIRECTORY, | 43 PARENT_TYPE_DIRECTORY, |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 const char kSyncRootDirectoryName[] = "Chrome Syncable FileSystem"; | |
| 46 const char kSyncRootDirectoryNameDev[] = "Chrome Syncable FileSystem Dev"; | |
| 47 const char kMimeTypeOctetStream[] = "application/octet-stream"; | |
| 48 | |
| 49 const char kFakeAccountId[] = "test_user@gmail.com"; | 46 const char kFakeAccountId[] = "test_user@gmail.com"; |
| 50 | 47 |
| 51 void EmptyGDataErrorCodeCallback(google_apis::GDataErrorCode error) {} | 48 void EmptyGDataErrorCodeCallback(google_apis::GDataErrorCode error) {} |
| 52 | 49 |
| 53 bool HasParentLinkTo(const ScopedVector<google_apis::Link>& links, | 50 bool HasParentLinkTo(const ScopedVector<google_apis::Link>& links, |
| 54 const std::string& parent_resource_id, | 51 const std::string& parent_resource_id, |
| 55 ParentType parent_type) { | 52 ParentType parent_type) { |
| 56 bool has_parent = false; | 53 bool has_parent = false; |
| 57 | 54 |
| 58 for (ScopedVector<google_apis::Link>::const_iterator itr = links.begin(); | 55 for (ScopedVector<google_apis::Link>::const_iterator itr = links.begin(); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 633 } |
| 637 | 634 |
| 638 DCHECK(!GetRootResourceId().empty()); | 635 DCHECK(!GetRootResourceId().empty()); |
| 639 EnsureSyncRootIsNotInMyDrive(sync_root_resource_id); | 636 EnsureSyncRootIsNotInMyDrive(sync_root_resource_id); |
| 640 } | 637 } |
| 641 | 638 |
| 642 // static | 639 // static |
| 643 // TODO(calvinlo): Delete this when Sync Directory Operations are supported by | 640 // TODO(calvinlo): Delete this when Sync Directory Operations are supported by |
| 644 // default. | 641 // default. |
| 645 std::string APIUtil::GetSyncRootDirectoryName() { | 642 std::string APIUtil::GetSyncRootDirectoryName() { |
| 646 return IsSyncFSDirectoryOperationEnabled() ? kSyncRootDirectoryNameDev | 643 return IsSyncFSDirectoryOperationEnabled() ? kSyncRootFolderTitleDev |
| 647 : kSyncRootDirectoryName; | 644 : kSyncRootFolderTitle; |
| 648 } | 645 } |
| 649 | 646 |
| 650 // static | 647 // static |
| 651 std::string APIUtil::OriginToDirectoryTitle(const GURL& origin) { | 648 std::string APIUtil::OriginToDirectoryTitle(const GURL& origin) { |
| 652 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); | 649 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); |
| 653 return origin.host(); | 650 return origin.host(); |
| 654 } | 651 } |
| 655 | 652 |
| 656 // static | 653 // static |
| 657 GURL APIUtil::DirectoryTitleToOrigin(const std::string& title) { | 654 GURL APIUtil::DirectoryTitleToOrigin(const std::string& title) { |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 } | 1124 } |
| 1128 | 1125 |
| 1129 std::string APIUtil::GetRootResourceId() const { | 1126 std::string APIUtil::GetRootResourceId() const { |
| 1130 if (IsDriveAPIDisabled()) | 1127 if (IsDriveAPIDisabled()) |
| 1131 return drive_service_->GetRootResourceId(); | 1128 return drive_service_->GetRootResourceId(); |
| 1132 return root_resource_id_; | 1129 return root_resource_id_; |
| 1133 } | 1130 } |
| 1134 | 1131 |
| 1135 } // namespace drive_backend | 1132 } // namespace drive_backend |
| 1136 } // namespace sync_file_system | 1133 } // namespace sync_file_system |
| OLD | NEW |