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/extensions/api/sync_file_system/sync_file_system_api.h" | 5 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 file_system_url.type(), | 85 file_system_url.type(), |
86 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, | 86 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, |
87 this))); | 87 this))); |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 void SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem( | 91 void SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem( |
92 base::File::Error error) { | 92 base::File::Error error) { |
93 // Repost to switch from IO thread to UI thread for SendResponse(). | 93 // Repost to switch from IO thread to UI thread for SendResponse(). |
94 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 94 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
96 BrowserThread::PostTask( | 96 BrowserThread::PostTask( |
97 BrowserThread::UI, | 97 BrowserThread::UI, |
98 FROM_HERE, | 98 FROM_HERE, |
99 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, this, | 99 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, this, |
100 error)); | 100 error)); |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
105 if (error != base::File::FILE_OK) { | 105 if (error != base::File::FILE_OK) { |
106 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); | 106 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); |
107 SetResult(new base::FundamentalValue(false)); | 107 SetResult(new base::FundamentalValue(false)); |
108 SendResponse(false); | 108 SendResponse(false); |
109 return; | 109 return; |
110 } | 110 } |
111 | 111 |
112 SetResult(new base::FundamentalValue(true)); | 112 SetResult(new base::FundamentalValue(true)); |
113 SendResponse(true); | 113 SendResponse(true); |
114 } | 114 } |
(...skipping 24 matching lines...) Expand all Loading... |
139 GetProfile(), render_view_host()->GetSiteInstance()) | 139 GetProfile(), render_view_host()->GetSiteInstance()) |
140 ->GetFileSystemContext(); | 140 ->GetFileSystemContext(); |
141 } | 141 } |
142 | 142 |
143 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( | 143 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( |
144 const GURL& root_url, | 144 const GURL& root_url, |
145 const std::string& file_system_name, | 145 const std::string& file_system_name, |
146 base::File::Error error) { | 146 base::File::Error error) { |
147 // Repost to switch from IO thread to UI thread for SendResponse(). | 147 // Repost to switch from IO thread to UI thread for SendResponse(). |
148 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 148 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 149 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
150 BrowserThread::PostTask( | 150 BrowserThread::PostTask( |
151 BrowserThread::UI, FROM_HERE, | 151 BrowserThread::UI, FROM_HERE, |
152 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, | 152 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, |
153 this, root_url, file_system_name, error)); | 153 this, root_url, file_system_name, error)); |
154 return; | 154 return; |
155 } | 155 } |
156 | 156 |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
158 if (error != base::File::FILE_OK) { | 158 if (error != base::File::FILE_OK) { |
159 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); | 159 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); |
160 SendResponse(false); | 160 SendResponse(false); |
161 return; | 161 return; |
162 } | 162 } |
163 | 163 |
164 base::DictionaryValue* dict = new base::DictionaryValue(); | 164 base::DictionaryValue* dict = new base::DictionaryValue(); |
165 SetResult(dict); | 165 SetResult(dict); |
166 dict->SetString("name", file_system_name); | 166 dict->SetString("name", file_system_name); |
167 dict->SetString("root", root_url.spec()); | 167 dict->SetString("root", root_url.spec()); |
(...skipping 13 matching lines...) Expand all Loading... |
181 | 181 |
182 GetSyncFileSystemService(GetProfile())->GetFileSyncStatus( | 182 GetSyncFileSystemService(GetProfile())->GetFileSyncStatus( |
183 file_system_url, | 183 file_system_url, |
184 Bind(&SyncFileSystemGetFileStatusFunction::DidGetFileStatus, this)); | 184 Bind(&SyncFileSystemGetFileStatusFunction::DidGetFileStatus, this)); |
185 return true; | 185 return true; |
186 } | 186 } |
187 | 187 |
188 void SyncFileSystemGetFileStatusFunction::DidGetFileStatus( | 188 void SyncFileSystemGetFileStatusFunction::DidGetFileStatus( |
189 const SyncStatusCode sync_status_code, | 189 const SyncStatusCode sync_status_code, |
190 const SyncFileStatus sync_file_status) { | 190 const SyncFileStatus sync_file_status) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 191 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
192 if (sync_status_code != sync_file_system::SYNC_STATUS_OK) { | 192 if (sync_status_code != sync_file_system::SYNC_STATUS_OK) { |
193 error_ = ErrorToString(sync_status_code); | 193 error_ = ErrorToString(sync_status_code); |
194 SendResponse(false); | 194 SendResponse(false); |
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 // Convert from C++ to JavaScript enum. | 198 // Convert from C++ to JavaScript enum. |
199 results_ = api::sync_file_system::GetFileStatus::Results::Create( | 199 results_ = api::sync_file_system::GetFileStatus::Results::Create( |
200 SyncFileStatusToExtensionEnum(sync_file_status)); | 200 SyncFileStatusToExtensionEnum(sync_file_status)); |
201 SendResponse(true); | 201 SendResponse(true); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 this, file_system_url)); | 236 this, file_system_url)); |
237 } | 237 } |
238 | 238 |
239 return true; | 239 return true; |
240 } | 240 } |
241 | 241 |
242 void SyncFileSystemGetFileStatusesFunction::DidGetFileStatus( | 242 void SyncFileSystemGetFileStatusesFunction::DidGetFileStatus( |
243 const fileapi::FileSystemURL& file_system_url, | 243 const fileapi::FileSystemURL& file_system_url, |
244 SyncStatusCode sync_status_code, | 244 SyncStatusCode sync_status_code, |
245 SyncFileStatus sync_file_status) { | 245 SyncFileStatus sync_file_status) { |
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
247 num_results_received_++; | 247 num_results_received_++; |
248 DCHECK_LE(num_results_received_, num_expected_results_); | 248 DCHECK_LE(num_results_received_, num_expected_results_); |
249 | 249 |
250 file_sync_statuses_[file_system_url] = | 250 file_sync_statuses_[file_system_url] = |
251 std::make_pair(sync_status_code, sync_file_status); | 251 std::make_pair(sync_status_code, sync_file_status); |
252 | 252 |
253 // Keep mapping file statuses until all of them have been received. | 253 // Keep mapping file statuses until all of them have been received. |
254 // TODO(calvinlo): Get rid of this check when batch version of | 254 // TODO(calvinlo): Get rid of this check when batch version of |
255 // GetFileSyncStatus(GURL urls[]); is added. | 255 // GetFileSyncStatus(GURL urls[]); is added. |
256 if (num_results_received_ < num_expected_results_) | 256 if (num_results_received_ < num_expected_results_) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, | 310 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, |
311 this))); | 311 this))); |
312 | 312 |
313 return true; | 313 return true; |
314 } | 314 } |
315 | 315 |
316 void SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota( | 316 void SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota( |
317 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 317 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
318 // Repost to switch from IO thread to UI thread for SendResponse(). | 318 // Repost to switch from IO thread to UI thread for SendResponse(). |
319 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 319 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 320 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
321 BrowserThread::PostTask( | 321 BrowserThread::PostTask( |
322 BrowserThread::UI, | 322 BrowserThread::UI, |
323 FROM_HERE, | 323 FROM_HERE, |
324 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this, | 324 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this, |
325 status, usage, quota)); | 325 status, usage, quota)); |
326 return; | 326 return; |
327 } | 327 } |
328 | 328 |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 329 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
330 if (status != quota::kQuotaStatusOk) { | 330 if (status != quota::kQuotaStatusOk) { |
331 error_ = QuotaStatusCodeToString(status); | 331 error_ = QuotaStatusCodeToString(status); |
332 SendResponse(false); | 332 SendResponse(false); |
333 return; | 333 return; |
334 } | 334 } |
335 | 335 |
336 api::sync_file_system::StorageInfo info; | 336 api::sync_file_system::StorageInfo info; |
337 info.usage_bytes = usage; | 337 info.usage_bytes = usage; |
338 info.quota_bytes = quota; | 338 info.quota_bytes = quota; |
339 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); | 339 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 bool SyncFileSystemGetServiceStatusFunction::RunImpl() { | 377 bool SyncFileSystemGetServiceStatusFunction::RunImpl() { |
378 sync_file_system::SyncFileSystemService* service = | 378 sync_file_system::SyncFileSystemService* service = |
379 GetSyncFileSystemService(GetProfile()); | 379 GetSyncFileSystemService(GetProfile()); |
380 results_ = api::sync_file_system::GetServiceStatus::Results::Create( | 380 results_ = api::sync_file_system::GetServiceStatus::Results::Create( |
381 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())); | 381 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())); |
382 return true; | 382 return true; |
383 } | 383 } |
384 | 384 |
385 } // namespace extensions | 385 } // namespace extensions |
OLD | NEW |