| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/gdata/drive_api_service.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/message_loop_proxy.h" | |
| 12 #include "chrome/browser/chromeos/gdata/drive_api_operations.h" | |
| 13 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | |
| 14 #include "chrome/browser/chromeos/gdata/gdata_util.h" | |
| 15 #include "chrome/browser/chromeos/gdata/operation_runner.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/common/net/url_util.h" | |
| 18 #include "content/public/browser/browser_thread.h" | |
| 19 | |
| 20 using content::BrowserThread; | |
| 21 | |
| 22 namespace gdata { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 // OAuth2 scopes for Drive API. | |
| 27 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; | |
| 28 const char kDriveAppsReadonlyScope[] = | |
| 29 "https://www.googleapis.com/auth/drive.apps.readonly"; | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 DriveAPIService::DriveAPIService() | |
| 34 : profile_(NULL), | |
| 35 runner_(NULL) { | |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 37 } | |
| 38 | |
| 39 DriveAPIService::~DriveAPIService() { | |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 41 } | |
| 42 | |
| 43 void DriveAPIService::Initialize(Profile* profile) { | |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 45 profile_ = profile; | |
| 46 | |
| 47 std::vector<std::string> scopes; | |
| 48 scopes.push_back(kDriveScope); | |
| 49 scopes.push_back(kDriveAppsReadonlyScope); | |
| 50 runner_.reset(new OperationRunner(profile, scopes)); | |
| 51 runner_->Initialize(); | |
| 52 } | |
| 53 | |
| 54 OperationRegistry* DriveAPIService::operation_registry() const { | |
| 55 return runner_->operation_registry(); | |
| 56 } | |
| 57 | |
| 58 void DriveAPIService::CancelAll() { | |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 60 runner_->CancelAll(); | |
| 61 } | |
| 62 | |
| 63 void DriveAPIService::Authenticate(const AuthStatusCallback& callback) { | |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 65 runner_->Authenticate(callback); | |
| 66 } | |
| 67 | |
| 68 void DriveAPIService::GetDocuments(const GURL& url, | |
| 69 int64 start_changestamp, | |
| 70 const std::string& search_query, | |
| 71 const std::string& directory_resource_id, | |
| 72 const GetDataCallback& callback) { | |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 74 | |
| 75 if (search_query.empty()) | |
| 76 GetChangelist(url, start_changestamp, callback); | |
| 77 else | |
| 78 GetFilelist(url, search_query, callback); | |
| 79 | |
| 80 return; | |
| 81 // TODO(kochi): Implement !directory_resource_id.empty() case. | |
| 82 NOTREACHED(); | |
| 83 } | |
| 84 | |
| 85 void DriveAPIService::GetFilelist(const GURL& url, | |
| 86 const std::string& search_query, | |
| 87 const GetDataCallback& callback) { | |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 89 | |
| 90 runner_->StartOperationWithRetry( | |
| 91 new GetFilelistOperation(operation_registry(), | |
| 92 url, | |
| 93 search_query, | |
| 94 callback)); | |
| 95 } | |
| 96 | |
| 97 void DriveAPIService::GetChangelist(const GURL& url, | |
| 98 int64 start_changestamp, | |
| 99 const GetDataCallback& callback) { | |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 101 | |
| 102 runner_->StartOperationWithRetry( | |
| 103 new GetChangelistOperation(operation_registry(), | |
| 104 url, | |
| 105 start_changestamp, | |
| 106 callback)); | |
| 107 } | |
| 108 | |
| 109 void DriveAPIService::GetDocumentEntry(const std::string& resource_id, | |
| 110 const GetDataCallback& callback) { | |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 112 | |
| 113 runner_->StartOperationWithRetry(new GetFileOperation(operation_registry(), | |
| 114 resource_id, | |
| 115 callback)); | |
| 116 } | |
| 117 | |
| 118 void DriveAPIService::GetAccountMetadata(const GetDataCallback& callback) { | |
| 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 120 | |
| 121 runner_->StartOperationWithRetry( | |
| 122 new GetAboutOperation(operation_registry(), callback)); | |
| 123 } | |
| 124 | |
| 125 void DriveAPIService::GetApplicationInfo(const GetDataCallback& callback) { | |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 127 | |
| 128 runner_->StartOperationWithRetry( | |
| 129 new GetApplistOperation(operation_registry(), callback)); | |
| 130 } | |
| 131 | |
| 132 void DriveAPIService::DownloadDocument( | |
| 133 const FilePath& virtual_path, | |
| 134 const FilePath& local_cache_path, | |
| 135 const GURL& document_url, | |
| 136 DocumentExportFormat format, | |
| 137 const DownloadActionCallback& callback) { | |
| 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 139 | |
| 140 // TODO(kochi): Implement this. | |
| 141 NOTREACHED(); | |
| 142 } | |
| 143 | |
| 144 void DriveAPIService::DownloadFile( | |
| 145 const FilePath& virtual_path, | |
| 146 const FilePath& local_cache_path, | |
| 147 const GURL& document_url, | |
| 148 const DownloadActionCallback& download_action_callback, | |
| 149 const GetContentCallback& get_content_callback) { | |
| 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 151 | |
| 152 // TODO(kochi): Implement this. | |
| 153 NOTREACHED(); | |
| 154 } | |
| 155 | |
| 156 void DriveAPIService::DeleteDocument(const GURL& document_url, | |
| 157 const EntryActionCallback& callback) { | |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 159 | |
| 160 // TODO(kochi): Implement this. | |
| 161 NOTREACHED(); | |
| 162 } | |
| 163 | |
| 164 void DriveAPIService::CreateDirectory( | |
| 165 const GURL& parent_content_url, | |
| 166 const FilePath::StringType& directory_name, | |
| 167 const GetDataCallback& callback) { | |
| 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 169 | |
| 170 // TODO(kochi): Implement this. | |
| 171 NOTREACHED(); | |
| 172 } | |
| 173 | |
| 174 void DriveAPIService::CopyDocument(const std::string& resource_id, | |
| 175 const FilePath::StringType& new_name, | |
| 176 const GetDataCallback& callback) { | |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 178 | |
| 179 // TODO(kochi): Implement this. | |
| 180 NOTREACHED(); | |
| 181 } | |
| 182 | |
| 183 void DriveAPIService::RenameResource(const GURL& resource_url, | |
| 184 const FilePath::StringType& new_name, | |
| 185 const EntryActionCallback& callback) { | |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 187 | |
| 188 // TODO(kochi): Implement this. | |
| 189 NOTREACHED(); | |
| 190 } | |
| 191 | |
| 192 void DriveAPIService::AddResourceToDirectory( | |
| 193 const GURL& parent_content_url, | |
| 194 const GURL& resource_url, | |
| 195 const EntryActionCallback& callback) { | |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 197 | |
| 198 // TODO(kochi): Implement this. | |
| 199 NOTREACHED(); | |
| 200 } | |
| 201 | |
| 202 void DriveAPIService::RemoveResourceFromDirectory( | |
| 203 const GURL& parent_content_url, | |
| 204 const GURL& resource_url, | |
| 205 const std::string& resource_id, | |
| 206 const EntryActionCallback& callback) { | |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 208 | |
| 209 // TODO(kochi): Implement this. | |
| 210 NOTREACHED(); | |
| 211 } | |
| 212 | |
| 213 void DriveAPIService::InitiateUpload(const InitiateUploadParams& params, | |
| 214 const InitiateUploadCallback& callback) { | |
| 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 216 | |
| 217 // TODO(kochi): Implement this. | |
| 218 NOTREACHED(); | |
| 219 } | |
| 220 | |
| 221 void DriveAPIService::ResumeUpload(const ResumeUploadParams& params, | |
| 222 const ResumeUploadCallback& callback) { | |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 224 | |
| 225 // TODO(kochi): Implement this. | |
| 226 NOTREACHED(); | |
| 227 } | |
| 228 | |
| 229 | |
| 230 void DriveAPIService::AuthorizeApp(const GURL& resource_url, | |
| 231 const std::string& app_ids, | |
| 232 const GetDataCallback& callback) { | |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 234 | |
| 235 // TODO(kochi): Implement this. | |
| 236 NOTREACHED(); | |
| 237 } | |
| 238 | |
| 239 bool DriveAPIService::HasAccessToken() const { | |
| 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 241 | |
| 242 return runner_->auth_service()->HasAccessToken(); | |
| 243 } | |
| 244 | |
| 245 bool DriveAPIService::HasRefreshToken() const { | |
| 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 247 | |
| 248 return runner_->auth_service()->HasRefreshToken(); | |
| 249 } | |
| 250 | |
| 251 } // namespace gdata | |
| OLD | NEW |