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

Unified 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: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/drive/fake_drive_service.h ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/drive/fake_drive_service.cc
diff --git a/chrome/browser/drive/fake_drive_service.cc b/chrome/browser/drive/fake_drive_service.cc
index 37cf9607d67385cfe9e796a6d8c00cf9d677d5ae..c69b2166b03cba0d4fc8678dc558c3d741ceae42 100644
--- a/chrome/browser/drive/fake_drive_service.cc
+++ b/chrome/browser/drive/fake_drive_service.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/file_util.h"
+#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/md5.h"
#include "base/message_loop/message_loop.h"
@@ -215,6 +216,65 @@ bool FakeDriveService::LoadAppListForDriveApi(
return app_info_value_;
}
+void FakeDriveService::AddApp(const std::string& app_id,
+ const std::string& app_name,
+ const std::string& product_id,
+ const std::string& create_url) {
+ if (app_json_template_.empty()) {
+ base::FilePath path =
+ test_util::GetTestFilePath("drive/applist_app_template.json");
+ CHECK(base::ReadFileToString(path, &app_json_template_));
+ }
+
+ std::string app_json = app_json_template_;
+ ReplaceSubstringsAfterOffset(&app_json, 0, "$AppId", app_id);
+ ReplaceSubstringsAfterOffset(&app_json, 0, "$AppName", app_name);
+ ReplaceSubstringsAfterOffset(&app_json, 0, "$ProductId", product_id);
+ ReplaceSubstringsAfterOffset(&app_json, 0, "$CreateUrl", create_url);
+
+ JSONStringValueSerializer json(app_json);
+ std::string error_message;
+ scoped_ptr<base::Value> value(json.Deserialize(NULL, &error_message));
+ CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType());
+
+ base::ListValue* item_list;
+ CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list));
+ item_list->Append(value.release());
+}
+
+void FakeDriveService::RemoveAppByProductId(const std::string& product_id) {
+ base::ListValue* item_list;
+ CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list));
+ for (size_t i = 0; i < item_list->GetSize(); ++i) {
+ base::DictionaryValue* item;
+ CHECK(item_list->GetDictionary(i, &item));
+ const char kKeyProductId[] = "productId";
+ std::string item_product_id;
+ if (item->GetStringWithoutPathExpansion(kKeyProductId, &item_product_id) &&
+ product_id == item_product_id) {
+ item_list->Remove(i, NULL);
+ return;
+ }
+ }
+}
+
+bool FakeDriveService::HasApp(const std::string& app_id) const {
+ base::ListValue* item_list;
+ CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list));
+ for (size_t i = 0; i < item_list->GetSize(); ++i) {
+ base::DictionaryValue* item;
+ CHECK(item_list->GetDictionary(i, &item));
+ const char kKeyId[] = "id";
+ std::string item_id;
+ if (item->GetStringWithoutPathExpansion(kKeyId, &item_id) &&
+ item_id == app_id) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void FakeDriveService::SetQuotaValue(int64 used, int64 total) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
« no previous file with comments | « chrome/browser/drive/fake_drive_service.h ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698