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 | 270 app_info_value_ = test_util::LoadJSONFile(relative_path); |
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())); | |
276 return app_info_value_; | 271 return app_info_value_; |
277 } | 272 } |
278 | 273 |
279 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { | 274 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { |
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
281 DCHECK(account_metadata_value_); | 276 DCHECK(account_metadata_value_); |
282 | 277 |
283 account_metadata_value_->SetString("entry.gd$quotaBytesUsed.$t", | 278 account_metadata_value_->SetString("entry.gd$quotaBytesUsed.$t", |
284 base::Int64ToString16(used)); | 279 base::Int64ToString16(used)); |
285 account_metadata_value_->SetString("entry.gd$quotaBytesTotal.$t", | 280 account_metadata_value_->SetString("entry.gd$quotaBytesTotal.$t", |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1260 DCHECK(!callback.is_null()); | 1255 DCHECK(!callback.is_null()); |
1261 return CancelCallback(); | 1256 return CancelCallback(); |
1262 } | 1257 } |
1263 | 1258 |
1264 CancelCallback FakeDriveService::UninstallApp( | 1259 CancelCallback FakeDriveService::UninstallApp( |
1265 const std::string& app_id, | 1260 const std::string& app_id, |
1266 const google_apis::EntryActionCallback& callback) { | 1261 const google_apis::EntryActionCallback& callback) { |
1267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1268 DCHECK(!callback.is_null()); | 1263 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)); | |
1292 return CancelCallback(); | 1264 return CancelCallback(); |
1293 } | 1265 } |
1294 | 1266 |
1295 CancelCallback FakeDriveService::GetResourceListInDirectoryByWapi( | 1267 CancelCallback FakeDriveService::GetResourceListInDirectoryByWapi( |
1296 const std::string& directory_resource_id, | 1268 const std::string& directory_resource_id, |
1297 const google_apis::GetResourceListCallback& callback) { | 1269 const google_apis::GetResourceListCallback& callback) { |
1298 return GetResourceListInDirectory( | 1270 return GetResourceListInDirectory( |
1299 directory_resource_id == util::kWapiRootDirectoryResourceId ? | 1271 directory_resource_id == util::kWapiRootDirectoryResourceId ? |
1300 GetRootResourceId() : | 1272 GetRootResourceId() : |
1301 directory_resource_id, | 1273 directory_resource_id, |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 FROM_HERE, | 1704 FROM_HERE, |
1733 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); | 1705 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_list))); |
1734 } | 1706 } |
1735 | 1707 |
1736 GURL FakeDriveService::GetNewUploadSessionUrl() { | 1708 GURL FakeDriveService::GetNewUploadSessionUrl() { |
1737 return GURL("https://upload_session_url/" + | 1709 return GURL("https://upload_session_url/" + |
1738 base::Int64ToString(next_upload_sequence_number_++)); | 1710 base::Int64ToString(next_upload_sequence_number_++)); |
1739 } | 1711 } |
1740 | 1712 |
1741 } // namespace drive | 1713 } // namespace drive |
OLD | NEW |