Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/drive/fake_drive_service.cc

Issue 308003005: app_list: Drive app integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pref is_syancable -> do_not_sync, remove AppListModel deps and no auto uninstall new_app Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_string_value_serializer.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/md5.h" 12 #include "base/md5.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
15 #include "base/strings/string_tokenizer.h" 16 #include "base/strings/string_tokenizer.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 20 #include "base/values.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
212 213
213 // Load JSON data, which must be a dictionary. 214 // Load JSON data, which must be a dictionary.
214 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); 215 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path);
215 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); 216 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType());
216 app_info_value_.reset( 217 app_info_value_.reset(
217 static_cast<base::DictionaryValue*>(value.release())); 218 static_cast<base::DictionaryValue*>(value.release()));
218 return app_info_value_; 219 return app_info_value_;
219 } 220 }
220 221
222 void FakeDriveService::AddApp(const std::string& app_id,
223 const std::string& app_name,
224 const std::string& product_id,
225 const std::string& create_url) {
226 if (app_json_template_.empty()) {
227 base::FilePath path =
228 test_util::GetTestFilePath("drive/applist_app_template.json");
229 CHECK(base::ReadFileToString(path, &app_json_template_));
230 }
231
232 std::string app_json = app_json_template_;
233 ReplaceSubstringsAfterOffset(&app_json, 0, "$AppId", app_id);
234 ReplaceSubstringsAfterOffset(&app_json, 0, "$AppName", app_name);
235 ReplaceSubstringsAfterOffset(&app_json, 0, "$ProductId", product_id);
236 ReplaceSubstringsAfterOffset(&app_json, 0, "$CreateUrl", create_url);
237
238 JSONStringValueSerializer json(app_json);
239 std::string error_message;
240 scoped_ptr<base::Value> value(json.Deserialize(NULL, &error_message));
241 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType());
242
243 base::ListValue* item_list;
244 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list));
245 item_list->Append(value.release());
246 }
247
248 void FakeDriveService::RemoveAppByProductId(const std::string& product_id) {
249 base::ListValue* item_list;
250 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list));
251 for (size_t i = 0; i < item_list->GetSize(); ++i) {
252 base::DictionaryValue* item;
253 CHECK(item_list->GetDictionary(i, &item));
254 const char kKeyProductId[] = "productId";
255 std::string item_product_id;
256 if (item->GetStringWithoutPathExpansion(kKeyProductId, &item_product_id) &&
257 product_id == item_product_id) {
258 item_list->Remove(i, NULL);
259 return;
260 }
261 }
262 }
263
264 bool FakeDriveService::HasApp(const std::string& app_id) const {
265 base::ListValue* item_list;
266 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list));
267 for (size_t i = 0; i < item_list->GetSize(); ++i) {
268 base::DictionaryValue* item;
269 CHECK(item_list->GetDictionary(i, &item));
270 const char kKeyId[] = "id";
271 std::string item_id;
272 if (item->GetStringWithoutPathExpansion(kKeyId, &item_id) &&
273 item_id == app_id) {
274 return true;
275 }
276 }
277
278 return false;
279 }
280
221 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { 281 void FakeDriveService::SetQuotaValue(int64 used, int64 total) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 283
224 about_resource_->set_quota_bytes_used(used); 284 about_resource_->set_quota_bytes_used(used);
225 about_resource_->set_quota_bytes_total(total); 285 about_resource_->set_quota_bytes_total(total);
226 } 286 }
227 287
228 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { 288 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) {
229 return GURL("https://fake_server/" + net::EscapePath(resource_id)); 289 return GURL("https://fake_server/" + net::EscapePath(resource_id));
230 } 290 }
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 google_apis::drive::PermissionRole role, 1584 google_apis::drive::PermissionRole role,
1525 const google_apis::EntryActionCallback& callback) { 1585 const google_apis::EntryActionCallback& callback) {
1526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1527 DCHECK(!callback.is_null()); 1587 DCHECK(!callback.is_null());
1528 1588
1529 NOTREACHED(); 1589 NOTREACHED();
1530 return CancelCallback(); 1590 return CancelCallback();
1531 } 1591 }
1532 1592
1533 } // namespace drive 1593 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698