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/sync_file_system/drive_file_sync_client.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/google_apis/drive_uploader.h" | 12 #include "chrome/browser/google_apis/drive_uploader.h" |
13 #include "chrome/browser/google_apis/gdata_wapi_service.h" | 13 #include "chrome/browser/google_apis/gdata_wapi_service.h" |
14 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 14 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
| 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "extensions/common/constants.h" |
15 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
16 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
17 | 19 |
18 namespace sync_file_system { | 20 namespace sync_file_system { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 const char kRootResourceId[] = ""; | 24 const char kRootResourceId[] = ""; |
23 const char kSyncRootDirectoryName[] = "Chrome Syncable FileSystem"; | 25 const char kSyncRootDirectoryName[] = "Chrome Syncable FileSystem"; |
24 const char kResourceLinkPrefix[] = | 26 const char kResourceLinkPrefix[] = |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), | 108 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), |
107 kRootResourceId, directory_name, callback)); | 109 kRootResourceId, directory_name, callback)); |
108 } | 110 } |
109 | 111 |
110 void DriveFileSyncClient::GetDriveDirectoryForOrigin( | 112 void DriveFileSyncClient::GetDriveDirectoryForOrigin( |
111 const std::string& sync_root_resource_id, | 113 const std::string& sync_root_resource_id, |
112 const GURL& origin, | 114 const GURL& origin, |
113 const ResourceIdCallback& callback) { | 115 const ResourceIdCallback& callback) { |
114 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
115 | 117 |
116 std::string directory_name(origin.spec()); | 118 std::string directory_name(OriginToDirectoryTitle(origin)); |
117 SearchFilesInDirectory( | 119 SearchFilesInDirectory( |
118 sync_root_resource_id, | 120 sync_root_resource_id, |
119 FormatTitleQuery(directory_name), | 121 FormatTitleQuery(directory_name), |
120 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), | 122 base::Bind(&DriveFileSyncClient::DidGetDirectory, AsWeakPtr(), |
121 sync_root_resource_id, directory_name, callback)); | 123 sync_root_resource_id, directory_name, callback)); |
122 } | 124 } |
123 | 125 |
124 void DriveFileSyncClient::DidGetDirectory( | 126 void DriveFileSyncClient::DidGetDirectory( |
125 const std::string& parent_resource_id, | 127 const std::string& parent_resource_id, |
126 const std::string& directory_name, | 128 const std::string& directory_name, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 const GDataErrorCallback& callback) { | 351 const GDataErrorCallback& callback) { |
350 DCHECK(CalledOnValidThread()); | 352 DCHECK(CalledOnValidThread()); |
351 drive_service_->GetDocumentEntry( | 353 drive_service_->GetDocumentEntry( |
352 resource_id, | 354 resource_id, |
353 base::Bind(&DriveFileSyncClient::DidGetDocumentEntryData, | 355 base::Bind(&DriveFileSyncClient::DidGetDocumentEntryData, |
354 AsWeakPtr(), | 356 AsWeakPtr(), |
355 base::Bind(&DriveFileSyncClient::DeleteFileInternal, | 357 base::Bind(&DriveFileSyncClient::DeleteFileInternal, |
356 AsWeakPtr(), remote_file_md5, callback))); | 358 AsWeakPtr(), remote_file_md5, callback))); |
357 } | 359 } |
358 | 360 |
| 361 // static |
| 362 std::string DriveFileSyncClient::OriginToDirectoryTitle(const GURL& origin) { |
| 363 DCHECK(origin.SchemeIs(extensions::kExtensionScheme)); |
| 364 return origin.host(); |
| 365 } |
| 366 |
| 367 // static |
| 368 GURL DriveFileSyncClient::DirectoryTitleToOrigin(const std::string& title) { |
| 369 return extensions::Extension::GetBaseURLFromExtensionId(title); |
| 370 } |
| 371 |
359 void DriveFileSyncClient::DidGetDocumentFeedData( | 372 void DriveFileSyncClient::DidGetDocumentFeedData( |
360 const DocumentFeedCallback& callback, | 373 const DocumentFeedCallback& callback, |
361 google_apis::GDataErrorCode error, | 374 google_apis::GDataErrorCode error, |
362 scoped_ptr<base::Value> data) { | 375 scoped_ptr<base::Value> data) { |
363 DCHECK(CalledOnValidThread()); | 376 DCHECK(CalledOnValidThread()); |
364 | 377 |
365 if (error != google_apis::HTTP_SUCCESS) { | 378 if (error != google_apis::HTTP_SUCCESS) { |
366 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); | 379 callback.Run(error, scoped_ptr<google_apis::DocumentFeed>()); |
367 return; | 380 return; |
368 } | 381 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 } | 611 } |
599 | 612 |
600 void DriveFileSyncClient::DidDeleteFile( | 613 void DriveFileSyncClient::DidDeleteFile( |
601 const GDataErrorCallback& callback, | 614 const GDataErrorCallback& callback, |
602 google_apis::GDataErrorCode error) { | 615 google_apis::GDataErrorCode error) { |
603 DCHECK(CalledOnValidThread()); | 616 DCHECK(CalledOnValidThread()); |
604 callback.Run(error); | 617 callback.Run(error); |
605 } | 618 } |
606 | 619 |
607 } // namespace sync_file_system | 620 } // namespace sync_file_system |
OLD | NEW |