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/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/fake_drive_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 return account_metadata_value_; | 264 return account_metadata_value_; |
265 } | 265 } |
266 | 266 |
267 bool FakeDriveService::LoadAppListForDriveApi( | 267 bool FakeDriveService::LoadAppListForDriveApi( |
268 const std::string& relative_path) { | 268 const std::string& relative_path) { |
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
270 app_info_value_ = test_util::LoadJSONFile(relative_path); | 270 |
| 271 // Load JSON data, which must be a dictionary. |
| 272 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); |
| 273 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
| 274 app_info_value_.reset( |
| 275 static_cast<base::DictionaryValue*>(value.release())); |
271 return app_info_value_; | 276 return app_info_value_; |
272 } | 277 } |
273 | 278 |
274 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { | 279 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { |
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
276 DCHECK(account_metadata_value_); | 281 DCHECK(account_metadata_value_); |
277 | 282 |
278 account_metadata_value_->SetString("entry.gd$quotaBytesUsed.$t", | 283 account_metadata_value_->SetString("entry.gd$quotaBytesUsed.$t", |
279 base::Int64ToString16(used)); | 284 base::Int64ToString16(used)); |
280 account_metadata_value_->SetString("entry.gd$quotaBytesTotal.$t", | 285 account_metadata_value_->SetString("entry.gd$quotaBytesTotal.$t", |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1255 DCHECK(!callback.is_null()); | 1260 DCHECK(!callback.is_null()); |
1256 return CancelCallback(); | 1261 return CancelCallback(); |
1257 } | 1262 } |
1258 | 1263 |
1259 CancelCallback FakeDriveService::UninstallApp( | 1264 CancelCallback FakeDriveService::UninstallApp( |
1260 const std::string& app_id, | 1265 const std::string& app_id, |
1261 const google_apis::EntryActionCallback& callback) { | 1266 const google_apis::EntryActionCallback& callback) { |
1262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1263 DCHECK(!callback.is_null()); | 1268 DCHECK(!callback.is_null()); |
| 1269 |
| 1270 // Find app_id from app_info_value_ and delete. |
| 1271 google_apis::GDataErrorCode error = google_apis::HTTP_NOT_FOUND; |
| 1272 if (offline_) { |
| 1273 error = google_apis::GDATA_NO_CONNECTION; |
| 1274 } else { |
| 1275 base::ListValue* items = NULL; |
| 1276 if (app_info_value_->GetList("items", &items)) { |
| 1277 for (size_t i = 0; i < items->GetSize(); ++i) { |
| 1278 base::DictionaryValue* item = NULL; |
| 1279 std::string id; |
| 1280 if (items->GetDictionary(i, &item) && item->GetString("id", &id) && |
| 1281 id == app_id) { |
| 1282 if (items->Remove(i, NULL)) |
| 1283 error = google_apis::HTTP_SUCCESS; |
| 1284 break; |
| 1285 } |
| 1286 } |
| 1287 } |
| 1288 } |
| 1289 |
| 1290 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 1291 base::Bind(callback, error)); |
1264 return CancelCallback(); | 1292 return CancelCallback(); |
1265 } | 1293 } |
1266 | 1294 |
1267 CancelCallback FakeDriveService::GetResourceListInDirectoryByWapi( | 1295 CancelCallback FakeDriveService::GetResourceListInDirectoryByWapi( |
1268 const std::string& directory_resource_id, | 1296 const std::string& directory_resource_id, |
1269 const google_apis::GetResourceListCallback& callback) { | 1297 const google_apis::GetResourceListCallback& callback) { |
1270 return GetResourceListInDirectory( | 1298 return GetResourceListInDirectory( |
1271 directory_resource_id == util::kWapiRootDirectoryResourceId ? | 1299 directory_resource_id == util::kWapiRootDirectoryResourceId ? |
1272 GetRootResourceId() : | 1300 GetRootResourceId() : |
1273 directory_resource_id, | 1301 directory_resource_id, |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 FROM_HERE, | 1732 FROM_HERE, |
1705 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); | 1733 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); |
1706 } | 1734 } |
1707 | 1735 |
1708 GURL FakeDriveService::GetNewUploadSessionUrl() { | 1736 GURL FakeDriveService::GetNewUploadSessionUrl() { |
1709 return GURL("https://upload_session_url/" + | 1737 return GURL("https://upload_session_url/" + |
1710 base::Int64ToString(next_upload_sequence_number_++)); | 1738 base::Int64ToString(next_upload_sequence_number_++)); |
1711 } | 1739 } |
1712 | 1740 |
1713 } // namespace drive | 1741 } // namespace drive |
OLD | NEW |