| 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/drive/drive_api_service.h" | 5 #include "chrome/browser/chromeos/drive/drive_api_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "chrome/browser/google_apis/drive_api_operations.h" | 12 #include "chrome/browser/google_apis/drive_api_operations.h" |
| 13 #include "chrome/browser/google_apis/gdata_operations.h" | 13 #include "chrome/browser/google_apis/gdata_operations.h" |
| 14 #include "chrome/browser/google_apis/gdata_util.h" | 14 #include "chrome/browser/google_apis/gdata_util.h" |
| 15 #include "chrome/browser/google_apis/operation_runner.h" | 15 #include "chrome/browser/google_apis/operation_runner.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/net/url_util.h" | 17 #include "chrome/common/net/url_util.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 | 21 |
| 22 namespace gdata { | 22 namespace drive { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // OAuth2 scopes for Drive API. | 26 // OAuth2 scopes for Drive API. |
| 27 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; | 27 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; |
| 28 const char kDriveAppsReadonlyScope[] = | 28 const char kDriveAppsReadonlyScope[] = |
| 29 "https://www.googleapis.com/auth/drive.apps.readonly"; | 29 "https://www.googleapis.com/auth/drive.apps.readonly"; |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 void DriveAPIService::Initialize(Profile* profile) { | 47 void DriveAPIService::Initialize(Profile* profile) { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 49 profile_ = profile; | 49 profile_ = profile; |
| 50 | 50 |
| 51 std::vector<std::string> scopes; | 51 std::vector<std::string> scopes; |
| 52 scopes.push_back(kDriveScope); | 52 scopes.push_back(kDriveScope); |
| 53 scopes.push_back(kDriveAppsReadonlyScope); | 53 scopes.push_back(kDriveAppsReadonlyScope); |
| 54 runner_.reset(new OperationRunner(profile, scopes)); | 54 runner_.reset(new gdata::OperationRunner(profile, scopes)); |
| 55 runner_->Initialize(); | 55 runner_->Initialize(); |
| 56 | 56 |
| 57 runner_->auth_service()->AddObserver(this); | 57 runner_->auth_service()->AddObserver(this); |
| 58 runner_->operation_registry()->AddObserver(this); | 58 runner_->operation_registry()->AddObserver(this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { | 61 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { |
| 62 observers_.AddObserver(observer); | 62 observers_.AddObserver(observer); |
| 63 } | 63 } |
| 64 | 64 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 void DriveAPIService::CancelAll() { | 75 void DriveAPIService::CancelAll() { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 runner_->CancelAll(); | 77 runner_->CancelAll(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool DriveAPIService::CancelForFilePath(const FilePath& file_path) { | 80 bool DriveAPIService::CancelForFilePath(const FilePath& file_path) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 return operation_registry()->CancelForFilePath(file_path); | 82 return operation_registry()->CancelForFilePath(file_path); |
| 83 } | 83 } |
| 84 | 84 |
| 85 OperationProgressStatusList DriveAPIService::GetProgressStatusList() const { | 85 gdata::OperationProgressStatusList |
| 86 DriveAPIService::GetProgressStatusList() const { |
| 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 87 return operation_registry()->GetProgressStatusList(); | 88 return operation_registry()->GetProgressStatusList(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void DriveAPIService::Authenticate(const AuthStatusCallback& callback) { | 91 void DriveAPIService::Authenticate(const gdata::AuthStatusCallback& callback) { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 92 runner_->Authenticate(callback); | 93 runner_->Authenticate(callback); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void DriveAPIService::GetDocuments(const GURL& url, | 96 void DriveAPIService::GetDocuments(const GURL& url, |
| 96 int64 start_changestamp, | 97 int64 start_changestamp, |
| 97 const std::string& search_query, | 98 const std::string& search_query, |
| 98 const std::string& directory_resource_id, | 99 const std::string& directory_resource_id, |
| 99 const GetDataCallback& callback) { | 100 const gdata::GetDataCallback& callback) { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 101 | 102 |
| 102 if (search_query.empty()) | 103 if (search_query.empty()) |
| 103 GetChangelist(url, start_changestamp, callback); | 104 GetChangelist(url, start_changestamp, callback); |
| 104 else | 105 else |
| 105 GetFilelist(url, search_query, callback); | 106 GetFilelist(url, search_query, callback); |
| 106 | 107 |
| 107 return; | 108 return; |
| 108 // TODO(kochi): Implement !directory_resource_id.empty() case. | 109 // TODO(kochi): Implement !directory_resource_id.empty() case. |
| 109 NOTREACHED(); | 110 NOTREACHED(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void DriveAPIService::GetFilelist(const GURL& url, | 113 void DriveAPIService::GetFilelist(const GURL& url, |
| 113 const std::string& search_query, | 114 const std::string& search_query, |
| 114 const GetDataCallback& callback) { | 115 const gdata::GetDataCallback& callback) { |
| 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 116 | 117 |
| 117 runner_->StartOperationWithRetry( | 118 runner_->StartOperationWithRetry( |
| 118 new GetFilelistOperation(operation_registry(), | 119 new gdata::GetFilelistOperation(operation_registry(), |
| 119 url, | 120 url, |
| 120 search_query, | 121 search_query, |
| 121 callback)); | 122 callback)); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void DriveAPIService::GetChangelist(const GURL& url, | 125 void DriveAPIService::GetChangelist(const GURL& url, |
| 125 int64 start_changestamp, | 126 int64 start_changestamp, |
| 126 const GetDataCallback& callback) { | 127 const gdata::GetDataCallback& callback) { |
| 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 128 | 129 |
| 129 runner_->StartOperationWithRetry( | 130 runner_->StartOperationWithRetry( |
| 130 new GetChangelistOperation(operation_registry(), | 131 new gdata::GetChangelistOperation(operation_registry(), |
| 131 url, | 132 url, |
| 132 start_changestamp, | 133 start_changestamp, |
| 133 callback)); | 134 callback)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void DriveAPIService::GetDocumentEntry(const std::string& resource_id, | 137 void DriveAPIService::GetDocumentEntry(const std::string& resource_id, |
| 137 const GetDataCallback& callback) { | 138 const gdata::GetDataCallback& callback) { |
| 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 139 | 140 |
| 140 runner_->StartOperationWithRetry(new GetFileOperation(operation_registry(), | 141 runner_->StartOperationWithRetry(new gdata::GetFileOperation( |
| 141 resource_id, | 142 operation_registry(), |
| 142 callback)); | 143 resource_id, |
| 144 callback)); |
| 143 } | 145 } |
| 144 | 146 |
| 145 void DriveAPIService::GetAccountMetadata(const GetDataCallback& callback) { | 147 void DriveAPIService::GetAccountMetadata( |
| 148 const gdata::GetDataCallback& callback) { |
| 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 147 | 150 |
| 148 runner_->StartOperationWithRetry( | 151 runner_->StartOperationWithRetry( |
| 149 new GetAboutOperation(operation_registry(), callback)); | 152 new gdata::GetAboutOperation(operation_registry(), callback)); |
| 150 } | 153 } |
| 151 | 154 |
| 152 void DriveAPIService::GetApplicationInfo(const GetDataCallback& callback) { | 155 void DriveAPIService::GetApplicationInfo( |
| 156 const gdata::GetDataCallback& callback) { |
| 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 154 | 158 |
| 155 runner_->StartOperationWithRetry( | 159 runner_->StartOperationWithRetry( |
| 156 new GetApplistOperation(operation_registry(), callback)); | 160 new gdata::GetApplistOperation(operation_registry(), callback)); |
| 157 } | 161 } |
| 158 | 162 |
| 159 void DriveAPIService::DownloadDocument( | 163 void DriveAPIService::DownloadDocument( |
| 160 const FilePath& virtual_path, | 164 const FilePath& virtual_path, |
| 161 const FilePath& local_cache_path, | 165 const FilePath& local_cache_path, |
| 162 const GURL& document_url, | 166 const GURL& document_url, |
| 163 DocumentExportFormat format, | 167 DocumentExportFormat format, |
| 164 const DownloadActionCallback& callback) { | 168 const gdata::DownloadActionCallback& callback) { |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 | 170 |
| 167 // TODO(kochi): Implement this. | 171 // TODO(kochi): Implement this. |
| 168 NOTREACHED(); | 172 NOTREACHED(); |
| 169 } | 173 } |
| 170 | 174 |
| 171 void DriveAPIService::DownloadFile( | 175 void DriveAPIService::DownloadFile( |
| 172 const FilePath& virtual_path, | 176 const FilePath& virtual_path, |
| 173 const FilePath& local_cache_path, | 177 const FilePath& local_cache_path, |
| 174 const GURL& document_url, | 178 const GURL& document_url, |
| 175 const DownloadActionCallback& download_action_callback, | 179 const gdata::DownloadActionCallback& download_action_callback, |
| 176 const GetContentCallback& get_content_callback) { | 180 const gdata::GetContentCallback& get_content_callback) { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 | 182 |
| 179 // TODO(kochi): Implement this. | 183 // TODO(kochi): Implement this. |
| 180 NOTREACHED(); | 184 NOTREACHED(); |
| 181 } | 185 } |
| 182 | 186 |
| 183 void DriveAPIService::DeleteDocument(const GURL& document_url, | 187 void DriveAPIService::DeleteDocument( |
| 184 const EntryActionCallback& callback) { | 188 const GURL& document_url, |
| 189 const gdata::EntryActionCallback& callback) { |
| 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 186 | 191 |
| 187 // TODO(kochi): Implement this. | 192 // TODO(kochi): Implement this. |
| 188 NOTREACHED(); | 193 NOTREACHED(); |
| 189 } | 194 } |
| 190 | 195 |
| 191 void DriveAPIService::CreateDirectory( | 196 void DriveAPIService::CreateDirectory( |
| 192 const GURL& parent_content_url, | 197 const GURL& parent_content_url, |
| 193 const FilePath::StringType& directory_name, | 198 const FilePath::StringType& directory_name, |
| 194 const GetDataCallback& callback) { | 199 const gdata::GetDataCallback& callback) { |
| 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 | 201 |
| 197 // TODO(kochi): Implement this. | 202 // TODO(kochi): Implement this. |
| 198 NOTREACHED(); | 203 NOTREACHED(); |
| 199 } | 204 } |
| 200 | 205 |
| 201 void DriveAPIService::CopyDocument(const std::string& resource_id, | 206 void DriveAPIService::CopyDocument(const std::string& resource_id, |
| 202 const FilePath::StringType& new_name, | 207 const FilePath::StringType& new_name, |
| 203 const GetDataCallback& callback) { | 208 const gdata::GetDataCallback& callback) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 205 | 210 |
| 206 // TODO(kochi): Implement this. | 211 // TODO(kochi): Implement this. |
| 207 NOTREACHED(); | 212 NOTREACHED(); |
| 208 } | 213 } |
| 209 | 214 |
| 210 void DriveAPIService::RenameResource(const GURL& resource_url, | 215 void DriveAPIService::RenameResource( |
| 211 const FilePath::StringType& new_name, | 216 const GURL& resource_url, |
| 212 const EntryActionCallback& callback) { | 217 const FilePath::StringType& new_name, |
| 218 const gdata::EntryActionCallback& callback) { |
| 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 214 | 220 |
| 215 // TODO(kochi): Implement this. | 221 // TODO(kochi): Implement this. |
| 216 NOTREACHED(); | 222 NOTREACHED(); |
| 217 } | 223 } |
| 218 | 224 |
| 219 void DriveAPIService::AddResourceToDirectory( | 225 void DriveAPIService::AddResourceToDirectory( |
| 220 const GURL& parent_content_url, | 226 const GURL& parent_content_url, |
| 221 const GURL& resource_url, | 227 const GURL& resource_url, |
| 222 const EntryActionCallback& callback) { | 228 const gdata::EntryActionCallback& callback) { |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 224 | 230 |
| 225 // TODO(kochi): Implement this. | 231 // TODO(kochi): Implement this. |
| 226 NOTREACHED(); | 232 NOTREACHED(); |
| 227 } | 233 } |
| 228 | 234 |
| 229 void DriveAPIService::RemoveResourceFromDirectory( | 235 void DriveAPIService::RemoveResourceFromDirectory( |
| 230 const GURL& parent_content_url, | 236 const GURL& parent_content_url, |
| 231 const GURL& resource_url, | 237 const GURL& resource_url, |
| 232 const std::string& resource_id, | 238 const std::string& resource_id, |
| 233 const EntryActionCallback& callback) { | 239 const gdata::EntryActionCallback& callback) { |
| 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 235 | 241 |
| 236 // TODO(kochi): Implement this. | 242 // TODO(kochi): Implement this. |
| 237 NOTREACHED(); | 243 NOTREACHED(); |
| 238 } | 244 } |
| 239 | 245 |
| 240 void DriveAPIService::InitiateUpload(const InitiateUploadParams& params, | 246 void DriveAPIService::InitiateUpload( |
| 241 const InitiateUploadCallback& callback) { | 247 const gdata::InitiateUploadParams& params, |
| 248 const gdata::InitiateUploadCallback& callback) { |
| 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 243 | 250 |
| 244 // TODO(kochi): Implement this. | 251 // TODO(kochi): Implement this. |
| 245 NOTREACHED(); | 252 NOTREACHED(); |
| 246 } | 253 } |
| 247 | 254 |
| 248 void DriveAPIService::ResumeUpload(const ResumeUploadParams& params, | 255 void DriveAPIService::ResumeUpload( |
| 249 const ResumeUploadCallback& callback) { | 256 const gdata::ResumeUploadParams& params, |
| 257 const gdata::ResumeUploadCallback& callback) { |
| 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 251 | 259 |
| 252 // TODO(kochi): Implement this. | 260 // TODO(kochi): Implement this. |
| 253 NOTREACHED(); | 261 NOTREACHED(); |
| 254 } | 262 } |
| 255 | 263 |
| 256 void DriveAPIService::AuthorizeApp(const GURL& resource_url, | 264 void DriveAPIService::AuthorizeApp(const GURL& resource_url, |
| 257 const std::string& app_ids, | 265 const std::string& app_ids, |
| 258 const GetDataCallback& callback) { | 266 const gdata::GetDataCallback& callback) { |
| 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 260 | 268 |
| 261 // TODO(kochi): Implement this. | 269 // TODO(kochi): Implement this. |
| 262 NOTREACHED(); | 270 NOTREACHED(); |
| 263 } | 271 } |
| 264 | 272 |
| 265 bool DriveAPIService::HasAccessToken() const { | 273 bool DriveAPIService::HasAccessToken() const { |
| 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 267 | 275 |
| 268 return runner_->auth_service()->HasAccessToken(); | 276 return runner_->auth_service()->HasAccessToken(); |
| 269 } | 277 } |
| 270 | 278 |
| 271 bool DriveAPIService::HasRefreshToken() const { | 279 bool DriveAPIService::HasRefreshToken() const { |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 273 | 281 |
| 274 return runner_->auth_service()->HasRefreshToken(); | 282 return runner_->auth_service()->HasRefreshToken(); |
| 275 } | 283 } |
| 276 | 284 |
| 277 OperationRegistry* DriveAPIService::operation_registry() const { | 285 gdata::OperationRegistry* DriveAPIService::operation_registry() const { |
| 278 return runner_->operation_registry(); | 286 return runner_->operation_registry(); |
| 279 } | 287 } |
| 280 | 288 |
| 281 void DriveAPIService::OnOAuth2RefreshTokenChanged() { | 289 void DriveAPIService::OnOAuth2RefreshTokenChanged() { |
| 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 283 if (CanStartOperation()) { | 291 if (CanStartOperation()) { |
| 284 FOR_EACH_OBSERVER( | 292 FOR_EACH_OBSERVER( |
| 285 DriveServiceObserver, observers_, OnReadyToPerformOperations()); | 293 DriveServiceObserver, observers_, OnReadyToPerformOperations()); |
| 286 } | 294 } |
| 287 } | 295 } |
| 288 | 296 |
| 289 void DriveAPIService::OnProgressUpdate( | 297 void DriveAPIService::OnProgressUpdate( |
| 290 const OperationProgressStatusList& list) { | 298 const gdata::OperationProgressStatusList& list) { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 292 FOR_EACH_OBSERVER( | 300 FOR_EACH_OBSERVER( |
| 293 DriveServiceObserver, observers_, OnProgressUpdate(list)); | 301 DriveServiceObserver, observers_, OnProgressUpdate(list)); |
| 294 } | 302 } |
| 295 | 303 |
| 296 void DriveAPIService::OnAuthenticationFailed(GDataErrorCode error) { | 304 void DriveAPIService::OnAuthenticationFailed(gdata::GDataErrorCode error) { |
| 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 298 FOR_EACH_OBSERVER( | 306 FOR_EACH_OBSERVER( |
| 299 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); | 307 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); |
| 300 } | 308 } |
| 301 | 309 |
| 302 } // namespace gdata | 310 } // namespace drive |
| OLD | NEW |