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/google_apis/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | |
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | |
10 #include "chrome/browser/google_apis/test_util.h" | |
8 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
9 | 12 |
10 using content::BrowserThread; | 13 using content::BrowserThread; |
11 | 14 |
12 namespace google_apis { | 15 namespace google_apis { |
13 | 16 |
14 FakeDriveService::FakeDriveService() { | 17 FakeDriveService::FakeDriveService() { |
15 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
16 } | 19 } |
17 | 20 |
18 FakeDriveService::~FakeDriveService() { | 21 FakeDriveService::~FakeDriveService() { |
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
20 } | 23 } |
21 | 24 |
25 bool FakeDriveService::LoadResourceListForWapi( | |
26 const std::string& relative_path) { | |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
28 scoped_ptr<Value> raw_value = test_util::LoadJSONFile(relative_path); | |
29 base::DictionaryValue* as_dict = NULL; | |
30 base::Value* feed = NULL; | |
31 base::DictionaryValue* feed_as_dict = NULL; | |
32 | |
33 // Extract the "feed" from the raw value and take the ownership. | |
34 if (raw_value->GetAsDictionary(&as_dict) && | |
35 as_dict->Remove("feed", &feed) && | |
36 feed->GetAsDictionary(&feed_as_dict)) { | |
37 resource_list_value_.reset(feed_as_dict); | |
kinaba
2013/01/08 08:26:53
Is this safe? |feed_as_dict| looks to be simultane
satorux1
2013/01/09 00:50:49
Should be safe. Remove() above transfers the owner
kinaba
2013/01/09 01:36:23
Ah, sorry, you're right.
| |
38 } | |
39 | |
40 return resource_list_value_; | |
41 } | |
42 | |
43 bool FakeDriveService::LoadAccountMetadataForWapi( | |
44 const std::string& relative_path) { | |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
46 account_metadata_value_ = test_util::LoadJSONFile(relative_path); | |
47 return account_metadata_value_; | |
48 } | |
49 | |
22 void FakeDriveService::Initialize(Profile* profile) { | 50 void FakeDriveService::Initialize(Profile* profile) { |
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
24 } | 52 } |
25 | 53 |
26 void FakeDriveService::AddObserver(DriveServiceObserver* observer) { | 54 void FakeDriveService::AddObserver(DriveServiceObserver* observer) { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
28 } | 56 } |
29 | 57 |
30 void FakeDriveService::RemoveObserver(DriveServiceObserver* observer) { | 58 void FakeDriveService::RemoveObserver(DriveServiceObserver* observer) { |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 29 matching lines...) Expand all Loading... | |
61 } | 89 } |
62 void FakeDriveService::GetResourceList( | 90 void FakeDriveService::GetResourceList( |
63 const GURL& feed_url, | 91 const GURL& feed_url, |
64 int64 start_changestamp, | 92 int64 start_changestamp, |
65 const std::string& search_query, | 93 const std::string& search_query, |
66 bool shared_with_me, | 94 bool shared_with_me, |
67 const std::string& directory_resource_id, | 95 const std::string& directory_resource_id, |
68 const GetResourceListCallback& callback) { | 96 const GetResourceListCallback& callback) { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
70 DCHECK(!callback.is_null()); | 98 DCHECK(!callback.is_null()); |
99 | |
100 scoped_ptr<ResourceList> resource_list = | |
101 ResourceList::CreateFrom(*resource_list_value_); | |
102 MessageLoop::current()->PostTask( | |
103 FROM_HERE, | |
104 base::Bind(callback, | |
105 HTTP_SUCCESS, | |
106 base::Passed(&resource_list))); | |
71 } | 107 } |
72 | 108 |
73 void FakeDriveService::GetResourceEntry( | 109 void FakeDriveService::GetResourceEntry( |
74 const std::string& resource_id, | 110 const std::string& resource_id, |
75 const GetResourceEntryCallback& callback) { | 111 const GetResourceEntryCallback& callback) { |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
77 DCHECK(!callback.is_null()); | 113 DCHECK(!callback.is_null()); |
114 | |
115 base::DictionaryValue* resource_list_dict = NULL; | |
116 base::ListValue* entries = NULL; | |
117 // Go through entries and return the one that matches |resource_id. | |
118 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | |
119 resource_list_dict->GetList("entry", &entries)) { | |
120 for (size_t i = 0; i < entries->GetSize(); ++i) { | |
121 base::DictionaryValue* entry = NULL; | |
122 base::DictionaryValue* resource_id_dict = NULL; | |
123 std::string current_resource_id; | |
124 if (entries->GetDictionary(i, &entry) && | |
125 entry->GetDictionary("gd$resourceId", &resource_id_dict) && | |
126 resource_id_dict->GetString("$t", ¤t_resource_id) && | |
127 resource_id == current_resource_id) { | |
128 scoped_ptr<ResourceEntry> resource_entry = | |
129 ResourceEntry::CreateFrom(*entry); | |
130 callback.Run(HTTP_SUCCESS, resource_entry.Pass()); | |
kinaba
2013/01/08 08:26:53
We should better do PostTask here as well as in Ge
satorux1
2013/01/09 00:50:49
Good catch! Done.
| |
131 return; | |
132 } | |
133 } | |
134 } | |
135 | |
136 callback.Run(HTTP_NOT_FOUND, scoped_ptr<ResourceEntry>(NULL)); | |
78 } | 137 } |
79 | 138 |
80 void FakeDriveService::GetAccountMetadata( | 139 void FakeDriveService::GetAccountMetadata( |
81 const GetAccountMetadataCallback& callback) { | 140 const GetAccountMetadataCallback& callback) { |
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
83 DCHECK(!callback.is_null()); | 142 DCHECK(!callback.is_null()); |
143 | |
144 scoped_ptr<AccountMetadataFeed> account_metadata = | |
145 AccountMetadataFeed::CreateFrom(*account_metadata_value_); | |
146 MessageLoop::current()->PostTask( | |
147 FROM_HERE, | |
148 base::Bind(callback, | |
149 HTTP_SUCCESS, | |
150 base::Passed(&account_metadata))); | |
84 } | 151 } |
85 | 152 |
86 void FakeDriveService::GetApplicationInfo( | 153 void FakeDriveService::GetApplicationInfo( |
87 const GetDataCallback& callback) { | 154 const GetDataCallback& callback) { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
89 DCHECK(!callback.is_null()); | 156 DCHECK(!callback.is_null()); |
90 } | 157 } |
91 | 158 |
92 void FakeDriveService::DeleteResource( | 159 void FakeDriveService::DeleteResource( |
93 const GURL& edit_url, | 160 const GURL& edit_url, |
94 const EntryActionCallback& callback) { | 161 const EntryActionCallback& callback) { |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
96 DCHECK(!callback.is_null()); | 163 DCHECK(!callback.is_null()); |
164 | |
165 base::DictionaryValue* resource_list_dict = NULL; | |
166 base::ListValue* entries = NULL; | |
167 // Go through entries and remove one that matches |edit_url|. | |
168 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | |
169 resource_list_dict->GetList("entry", &entries)) { | |
170 for (size_t i = 0; i < entries->GetSize(); ++i) { | |
171 base::DictionaryValue* entry = NULL; | |
172 base::ListValue* links = NULL; | |
173 if (entries->GetDictionary(i, &entry) && | |
174 entry->GetList("link", &links)) { | |
175 for (size_t j = 0; j < links->GetSize(); ++j) { | |
176 base::DictionaryValue* link = NULL; | |
177 std::string rel; | |
178 std::string href; | |
179 if (links->GetDictionary(j, &link) && | |
180 link->GetString("rel", &rel) && | |
181 link->GetString("href", &href) && | |
182 rel == "edit" && | |
183 GURL(href) == edit_url) { | |
184 entries->Remove(i, NULL); | |
185 callback.Run(HTTP_SUCCESS); | |
186 return; | |
187 } | |
188 } | |
189 } | |
190 } | |
191 } | |
192 | |
193 callback.Run(HTTP_NOT_FOUND); | |
97 } | 194 } |
98 | 195 |
99 void FakeDriveService::DownloadHostedDocument( | 196 void FakeDriveService::DownloadHostedDocument( |
100 const FilePath& virtual_path, | 197 const FilePath& virtual_path, |
101 const FilePath& local_cache_path, | 198 const FilePath& local_cache_path, |
102 const GURL& content_url, | 199 const GURL& content_url, |
103 DocumentExportFormat format, | 200 DocumentExportFormat format, |
104 const DownloadActionCallback& callback) { | 201 const DownloadActionCallback& callback) { |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
106 DCHECK(!callback.is_null()); | 203 DCHECK(!callback.is_null()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 } | 267 } |
171 | 268 |
172 void FakeDriveService::AuthorizeApp(const GURL& edit_url, | 269 void FakeDriveService::AuthorizeApp(const GURL& edit_url, |
173 const std::string& app_id, | 270 const std::string& app_id, |
174 const AuthorizeAppCallback& callback) { | 271 const AuthorizeAppCallback& callback) { |
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
176 DCHECK(!callback.is_null()); | 273 DCHECK(!callback.is_null()); |
177 } | 274 } |
178 | 275 |
179 } // namespace google_apis | 276 } // namespace google_apis |
OLD | NEW |