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" | 8 #include "base/message_loop.h" |
| 9 #include "base/stringprintf.h" |
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 10 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
10 #include "chrome/browser/google_apis/test_util.h" | 11 #include "chrome/browser/google_apis/test_util.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 | 13 |
13 using content::BrowserThread; | 14 using content::BrowserThread; |
14 | 15 |
15 namespace google_apis { | 16 namespace google_apis { |
16 | 17 |
17 FakeDriveService::FakeDriveService() { | 18 FakeDriveService::FakeDriveService() |
| 19 : resource_id_count_(0) { |
18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
19 } | 21 } |
20 | 22 |
21 FakeDriveService::~FakeDriveService() { | 23 FakeDriveService::~FakeDriveService() { |
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
23 } | 25 } |
24 | 26 |
25 bool FakeDriveService::LoadResourceListForWapi( | 27 bool FakeDriveService::LoadResourceListForWapi( |
26 const std::string& relative_path) { | 28 const std::string& relative_path) { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 13 matching lines...) Expand all Loading... |
41 return resource_list_value_; | 43 return resource_list_value_; |
42 } | 44 } |
43 | 45 |
44 bool FakeDriveService::LoadAccountMetadataForWapi( | 46 bool FakeDriveService::LoadAccountMetadataForWapi( |
45 const std::string& relative_path) { | 47 const std::string& relative_path) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 account_metadata_value_ = test_util::LoadJSONFile(relative_path); | 49 account_metadata_value_ = test_util::LoadJSONFile(relative_path); |
48 return account_metadata_value_; | 50 return account_metadata_value_; |
49 } | 51 } |
50 | 52 |
| 53 bool FakeDriveService::LoadApplicationInfoForDriveApi( |
| 54 const std::string& relative_path) { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 56 app_info_value_ = test_util::LoadJSONFile(relative_path); |
| 57 return app_info_value_; |
| 58 } |
| 59 |
51 void FakeDriveService::Initialize(Profile* profile) { | 60 void FakeDriveService::Initialize(Profile* profile) { |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
53 } | 62 } |
54 | 63 |
55 void FakeDriveService::AddObserver(DriveServiceObserver* observer) { | 64 void FakeDriveService::AddObserver(DriveServiceObserver* observer) { |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
57 } | 66 } |
58 | 67 |
59 void FakeDriveService::RemoveObserver(DriveServiceObserver* observer) { | 68 void FakeDriveService::RemoveObserver(DriveServiceObserver* observer) { |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 HTTP_SUCCESS, | 115 HTTP_SUCCESS, |
107 base::Passed(&resource_list))); | 116 base::Passed(&resource_list))); |
108 } | 117 } |
109 | 118 |
110 void FakeDriveService::GetResourceEntry( | 119 void FakeDriveService::GetResourceEntry( |
111 const std::string& resource_id, | 120 const std::string& resource_id, |
112 const GetResourceEntryCallback& callback) { | 121 const GetResourceEntryCallback& callback) { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
114 DCHECK(!callback.is_null()); | 123 DCHECK(!callback.is_null()); |
115 | 124 |
116 base::DictionaryValue* resource_list_dict = NULL; | 125 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
117 base::ListValue* entries = NULL; | 126 if (entry) { |
118 // Go through entries and return the one that matches |resource_id|. | 127 scoped_ptr<ResourceEntry> resource_entry = |
119 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | 128 ResourceEntry::CreateFrom(*entry); |
120 resource_list_dict->GetList("entry", &entries)) { | 129 MessageLoop::current()->PostTask( |
121 for (size_t i = 0; i < entries->GetSize(); ++i) { | 130 FROM_HERE, |
122 base::DictionaryValue* entry = NULL; | 131 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); |
123 base::DictionaryValue* resource_id_dict = NULL; | 132 return; |
124 std::string current_resource_id; | |
125 if (entries->GetDictionary(i, &entry) && | |
126 entry->GetDictionary("gd$resourceId", &resource_id_dict) && | |
127 resource_id_dict->GetString("$t", ¤t_resource_id) && | |
128 resource_id == current_resource_id) { | |
129 scoped_ptr<ResourceEntry> resource_entry = | |
130 ResourceEntry::CreateFrom(*entry); | |
131 MessageLoop::current()->PostTask( | |
132 FROM_HERE, | |
133 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); | |
134 return; | |
135 } | |
136 } | |
137 } | 133 } |
138 | 134 |
139 scoped_ptr<ResourceEntry> null; | 135 scoped_ptr<ResourceEntry> null; |
140 MessageLoop::current()->PostTask( | 136 MessageLoop::current()->PostTask( |
141 FROM_HERE, | 137 FROM_HERE, |
142 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | 138 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
143 } | 139 } |
144 | 140 |
145 void FakeDriveService::GetAccountMetadata( | 141 void FakeDriveService::GetAccountMetadata( |
146 const GetAccountMetadataCallback& callback) { | 142 const GetAccountMetadataCallback& callback) { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
148 DCHECK(!callback.is_null()); | 144 DCHECK(!callback.is_null()); |
149 | 145 |
150 scoped_ptr<AccountMetadataFeed> account_metadata = | 146 scoped_ptr<AccountMetadataFeed> account_metadata = |
151 AccountMetadataFeed::CreateFrom(*account_metadata_value_); | 147 AccountMetadataFeed::CreateFrom(*account_metadata_value_); |
152 MessageLoop::current()->PostTask( | 148 MessageLoop::current()->PostTask( |
153 FROM_HERE, | 149 FROM_HERE, |
154 base::Bind(callback, | 150 base::Bind(callback, |
155 HTTP_SUCCESS, | 151 HTTP_SUCCESS, |
156 base::Passed(&account_metadata))); | 152 base::Passed(&account_metadata))); |
157 } | 153 } |
158 | 154 |
159 void FakeDriveService::GetApplicationInfo( | 155 void FakeDriveService::GetApplicationInfo( |
160 const GetDataCallback& callback) { | 156 const GetDataCallback& callback) { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
162 DCHECK(!callback.is_null()); | 158 DCHECK(!callback.is_null()); |
| 159 |
| 160 scoped_ptr<base::Value> copied_app_info_value( |
| 161 app_info_value_->DeepCopy()); |
| 162 MessageLoop::current()->PostTask( |
| 163 FROM_HERE, |
| 164 base::Bind(callback, |
| 165 HTTP_SUCCESS, |
| 166 base::Passed(&copied_app_info_value))); |
| 167 |
163 } | 168 } |
164 | 169 |
165 void FakeDriveService::DeleteResource( | 170 void FakeDriveService::DeleteResource( |
166 const GURL& edit_url, | 171 const GURL& edit_url, |
167 const EntryActionCallback& callback) { | 172 const EntryActionCallback& callback) { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
169 DCHECK(!callback.is_null()); | 174 DCHECK(!callback.is_null()); |
170 | 175 |
171 base::DictionaryValue* resource_list_dict = NULL; | 176 base::DictionaryValue* resource_list_dict = NULL; |
172 base::ListValue* entries = NULL; | 177 base::ListValue* entries = NULL; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
221 DCHECK(!download_action_callback.is_null()); | 226 DCHECK(!download_action_callback.is_null()); |
222 } | 227 } |
223 | 228 |
224 void FakeDriveService::CopyHostedDocument( | 229 void FakeDriveService::CopyHostedDocument( |
225 const std::string& resource_id, | 230 const std::string& resource_id, |
226 const FilePath::StringType& new_name, | 231 const FilePath::StringType& new_name, |
227 const GetResourceEntryCallback& callback) { | 232 const GetResourceEntryCallback& callback) { |
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
229 DCHECK(!callback.is_null()); | 234 DCHECK(!callback.is_null()); |
| 235 |
| 236 base::DictionaryValue* resource_list_dict = NULL; |
| 237 base::ListValue* entries = NULL; |
| 238 // Go through entries and copy the one that matches |resource_id|. |
| 239 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 240 resource_list_dict->GetList("entry", &entries)) { |
| 241 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 242 base::DictionaryValue* entry = NULL; |
| 243 base::DictionaryValue* resource_id_dict = NULL; |
| 244 base::ListValue* categories = NULL; |
| 245 std::string current_resource_id; |
| 246 if (entries->GetDictionary(i, &entry) && |
| 247 entry->GetDictionary("gd$resourceId", &resource_id_dict) && |
| 248 resource_id_dict->GetString("$t", ¤t_resource_id) && |
| 249 resource_id == current_resource_id && |
| 250 entry->GetList("category", &categories)) { |
| 251 // Check that the resource is a hosted document. We consider it a |
| 252 // hosted document if the kind is neither "folder" nor "file". |
| 253 for (size_t k = 0; k < categories->GetSize(); ++k) { |
| 254 base::DictionaryValue* category = NULL; |
| 255 std::string scheme, term; |
| 256 if (categories->GetDictionary(k, &category) && |
| 257 category->GetString("scheme", &scheme) && |
| 258 category->GetString("term", &term) && |
| 259 scheme == "http://schemas.google.com/g/2005#kind" && |
| 260 term != "http://schemas.google.com/docs/2007#file" && |
| 261 term != "http://schemas.google.com/docs/2007#folder") { |
| 262 // Make a copy and set the new resource ID and the new title. |
| 263 scoped_ptr<DictionaryValue> copied_entry(entry->DeepCopy()); |
| 264 copied_entry->SetString("gd$resourceId.$t", |
| 265 resource_id + "_copied"); |
| 266 copied_entry->SetString("title.$t", |
| 267 FilePath(new_name).AsUTF8Unsafe()); |
| 268 // Parse the new entry. |
| 269 scoped_ptr<ResourceEntry> resource_entry = |
| 270 ResourceEntry::CreateFrom(*copied_entry); |
| 271 // Add it to the resource list. |
| 272 entries->Append(copied_entry.release()); |
| 273 |
| 274 MessageLoop::current()->PostTask( |
| 275 FROM_HERE, |
| 276 base::Bind(callback, |
| 277 HTTP_SUCCESS, |
| 278 base::Passed(&resource_entry))); |
| 279 return; |
| 280 } |
| 281 } |
| 282 } |
| 283 } |
| 284 } |
| 285 |
| 286 scoped_ptr<ResourceEntry> null; |
| 287 MessageLoop::current()->PostTask( |
| 288 FROM_HERE, |
| 289 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
230 } | 290 } |
231 | 291 |
232 void FakeDriveService::RenameResource( | 292 void FakeDriveService::RenameResource( |
233 const GURL& edit_url, | 293 const GURL& edit_url, |
234 const FilePath::StringType& new_name, | 294 const FilePath::StringType& new_name, |
235 const EntryActionCallback& callback) { | 295 const EntryActionCallback& callback) { |
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
237 DCHECK(!callback.is_null()); | 297 DCHECK(!callback.is_null()); |
| 298 |
| 299 base::DictionaryValue* entry = FindEntryByEditUrl(edit_url); |
| 300 if (entry) { |
| 301 entry->SetString("title.$t", |
| 302 FilePath(new_name).AsUTF8Unsafe()); |
| 303 MessageLoop::current()->PostTask( |
| 304 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); |
| 305 return; |
| 306 } |
| 307 |
| 308 MessageLoop::current()->PostTask( |
| 309 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
238 } | 310 } |
239 | 311 |
240 void FakeDriveService::AddResourceToDirectory( | 312 void FakeDriveService::AddResourceToDirectory( |
241 const GURL& parent_content_url, | 313 const GURL& parent_content_url, |
242 const GURL& edit_url, | 314 const GURL& edit_url, |
243 const EntryActionCallback& callback) { | 315 const EntryActionCallback& callback) { |
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
245 DCHECK(!callback.is_null()); | 317 DCHECK(!callback.is_null()); |
| 318 |
| 319 base::DictionaryValue* entry = FindEntryByEditUrl(edit_url); |
| 320 if (entry) { |
| 321 base::ListValue* links = NULL; |
| 322 if (entry->GetList("link", &links)) { |
| 323 bool parent_link_found = false; |
| 324 for (size_t i = 0; i < links->GetSize(); ++i) { |
| 325 base::DictionaryValue* link = NULL; |
| 326 std::string rel; |
| 327 if (links->GetDictionary(i, &link) && |
| 328 link->GetString("rel", &rel) && |
| 329 rel == "http://schemas.google.com/docs/2007#parent") { |
| 330 link->SetString("href", parent_content_url.spec()); |
| 331 parent_link_found = true; |
| 332 } |
| 333 } |
| 334 // The parent link does not exist if a resource is in the root |
| 335 // directory. |
| 336 if (!parent_link_found) { |
| 337 base::DictionaryValue* link = new base::DictionaryValue; |
| 338 link->SetString("rel", "http://schemas.google.com/docs/2007#parent"); |
| 339 link->SetString("href", parent_content_url.spec()); |
| 340 links->Append(link); |
| 341 } |
| 342 |
| 343 MessageLoop::current()->PostTask( |
| 344 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); |
| 345 return; |
| 346 } |
| 347 } |
| 348 |
| 349 MessageLoop::current()->PostTask( |
| 350 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
246 } | 351 } |
247 | 352 |
248 void FakeDriveService::RemoveResourceFromDirectory( | 353 void FakeDriveService::RemoveResourceFromDirectory( |
249 const GURL& parent_content_url, | 354 const GURL& parent_content_url, |
250 const std::string& resource_id, | 355 const std::string& resource_id, |
251 const EntryActionCallback& callback) { | 356 const EntryActionCallback& callback) { |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
253 DCHECK(!callback.is_null()); | 358 DCHECK(!callback.is_null()); |
| 359 |
| 360 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 361 if (entry) { |
| 362 base::ListValue* links = NULL; |
| 363 if (entry->GetList("link", &links)) { |
| 364 for (size_t i = 0; i < links->GetSize(); ++i) { |
| 365 base::DictionaryValue* link = NULL; |
| 366 std::string rel; |
| 367 std::string href; |
| 368 if (links->GetDictionary(i, &link) && |
| 369 link->GetString("rel", &rel) && |
| 370 link->GetString("href", &href) && |
| 371 rel == "http://schemas.google.com/docs/2007#parent" && |
| 372 GURL(href) == parent_content_url) { |
| 373 links->Remove(i, NULL); |
| 374 MessageLoop::current()->PostTask( |
| 375 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); |
| 376 return; |
| 377 } |
| 378 } |
| 379 } |
| 380 } |
| 381 |
| 382 MessageLoop::current()->PostTask( |
| 383 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
254 } | 384 } |
255 | 385 |
256 void FakeDriveService::AddNewDirectory( | 386 void FakeDriveService::AddNewDirectory( |
257 const GURL& parent_content_url, | 387 const GURL& parent_content_url, |
258 const FilePath::StringType& directory_name, | 388 const FilePath::StringType& directory_name, |
259 const GetResourceEntryCallback& callback) { | 389 const GetResourceEntryCallback& callback) { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
261 DCHECK(!callback.is_null()); | 391 DCHECK(!callback.is_null()); |
| 392 |
| 393 // If the parent content URL is not empty, the parent should exist. |
| 394 if (!parent_content_url.is_empty()) { |
| 395 base::DictionaryValue* parent_entry = |
| 396 FindEntryByContentUrl(parent_content_url); |
| 397 if (!parent_entry) { |
| 398 scoped_ptr<ResourceEntry> null; |
| 399 MessageLoop::current()->PostTask( |
| 400 FROM_HERE, |
| 401 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 402 return; |
| 403 } |
| 404 } |
| 405 |
| 406 const std::string new_resource_id = GetNewResourceId(); |
| 407 |
| 408 scoped_ptr<base::DictionaryValue> new_entry(new base::DictionaryValue); |
| 409 // Set the resource ID and the title |
| 410 new_entry->SetString("gd$resourceId.$t", new_resource_id); |
| 411 new_entry->SetString("title.$t", FilePath(directory_name).AsUTF8Unsafe()); |
| 412 |
| 413 // Add "category" which sets the resource type to folder. |
| 414 base::ListValue* categories = new base::ListValue; |
| 415 base::DictionaryValue* category = new base::DictionaryValue; |
| 416 category->SetString("label", "folder"); |
| 417 category->SetString("scheme", "http://schemas.google.com/g/2005#kind"); |
| 418 category->SetString("term", "http://schemas.google.com/docs/2007#folder"); |
| 419 categories->Append(category); |
| 420 new_entry->Set("category", categories); |
| 421 |
| 422 // Add "content" which sets the content URL. |
| 423 base::DictionaryValue* content = new base::DictionaryValue; |
| 424 content->SetString("src", "https://xxx/content/" + new_resource_id); |
| 425 new_entry->Set("content", content); |
| 426 |
| 427 // Add "link" which sets the parent URL and the edit URL. |
| 428 base::ListValue* links = new base::ListValue; |
| 429 if (!parent_content_url.is_empty()) { |
| 430 base::DictionaryValue* parent_link = new base::DictionaryValue; |
| 431 parent_link->SetString("href", parent_content_url.spec()); |
| 432 parent_link->SetString("rel", |
| 433 "http://schemas.google.com/docs/2007#parent"); |
| 434 links->Append(parent_link); |
| 435 } |
| 436 base::DictionaryValue* edit_link = new base::DictionaryValue; |
| 437 edit_link->SetString("href", "https://xxx/edit/" + new_resource_id); |
| 438 edit_link->SetString("rel", "edit"); |
| 439 links->Append(edit_link); |
| 440 new_entry->Set("link", links); |
| 441 |
| 442 // Add the new entry to the resource list. |
| 443 base::DictionaryValue* resource_list_dict = NULL; |
| 444 base::ListValue* entries = NULL; |
| 445 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 446 resource_list_dict->GetList("entry", &entries)) { |
| 447 // Parse the entry before releasing it. |
| 448 scoped_ptr<ResourceEntry> parsed_entry( |
| 449 ResourceEntry::CreateFrom(*new_entry)); |
| 450 |
| 451 entries->Append(new_entry.release()); |
| 452 |
| 453 MessageLoop::current()->PostTask( |
| 454 FROM_HERE, |
| 455 base::Bind(callback, HTTP_SUCCESS, base::Passed(&parsed_entry))); |
| 456 return; |
| 457 } |
| 458 |
| 459 scoped_ptr<ResourceEntry> null; |
| 460 MessageLoop::current()->PostTask( |
| 461 FROM_HERE, |
| 462 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
262 } | 463 } |
263 | 464 |
264 void FakeDriveService::InitiateUpload( | 465 void FakeDriveService::InitiateUpload( |
265 const InitiateUploadParams& params, | 466 const InitiateUploadParams& params, |
266 const InitiateUploadCallback& callback) { | 467 const InitiateUploadCallback& callback) { |
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
268 DCHECK(!callback.is_null()); | 469 DCHECK(!callback.is_null()); |
269 } | 470 } |
270 | 471 |
271 void FakeDriveService::ResumeUpload(const ResumeUploadParams& params, | 472 void FakeDriveService::ResumeUpload(const ResumeUploadParams& params, |
272 const ResumeUploadCallback& callback) { | 473 const ResumeUploadCallback& callback) { |
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
274 DCHECK(!callback.is_null()); | 475 DCHECK(!callback.is_null()); |
275 } | 476 } |
276 | 477 |
277 void FakeDriveService::AuthorizeApp(const GURL& edit_url, | 478 void FakeDriveService::AuthorizeApp(const GURL& edit_url, |
278 const std::string& app_id, | 479 const std::string& app_id, |
279 const AuthorizeAppCallback& callback) { | 480 const AuthorizeAppCallback& callback) { |
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
281 DCHECK(!callback.is_null()); | 482 DCHECK(!callback.is_null()); |
282 } | 483 } |
283 | 484 |
| 485 base::DictionaryValue* FakeDriveService::FindEntryByResourceId( |
| 486 const std::string& resource_id) { |
| 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 488 |
| 489 base::DictionaryValue* resource_list_dict = NULL; |
| 490 base::ListValue* entries = NULL; |
| 491 // Go through entries and return the one that matches |resource_id|. |
| 492 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 493 resource_list_dict->GetList("entry", &entries)) { |
| 494 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 495 base::DictionaryValue* entry = NULL; |
| 496 base::DictionaryValue* resource_id_dict = NULL; |
| 497 std::string current_resource_id; |
| 498 if (entries->GetDictionary(i, &entry) && |
| 499 entry->GetDictionary("gd$resourceId", &resource_id_dict) && |
| 500 resource_id_dict->GetString("$t", ¤t_resource_id) && |
| 501 resource_id == current_resource_id) { |
| 502 return entry; |
| 503 } |
| 504 } |
| 505 } |
| 506 |
| 507 return NULL; |
| 508 } |
| 509 |
| 510 base::DictionaryValue* FakeDriveService::FindEntryByEditUrl( |
| 511 const GURL& edit_url) { |
| 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 513 |
| 514 base::DictionaryValue* resource_list_dict = NULL; |
| 515 base::ListValue* entries = NULL; |
| 516 // Go through entries and return the one that matches |edit_url|. |
| 517 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 518 resource_list_dict->GetList("entry", &entries)) { |
| 519 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 520 base::DictionaryValue* entry = NULL; |
| 521 base::ListValue* links = NULL; |
| 522 if (entries->GetDictionary(i, &entry) && |
| 523 entry->GetList("link", &links)) { |
| 524 for (size_t j = 0; j < links->GetSize(); ++j) { |
| 525 base::DictionaryValue* link = NULL; |
| 526 std::string rel; |
| 527 std::string href; |
| 528 if (links->GetDictionary(j, &link) && |
| 529 link->GetString("rel", &rel) && |
| 530 link->GetString("href", &href) && |
| 531 rel == "edit" && |
| 532 GURL(href) == edit_url) { |
| 533 return entry; |
| 534 } |
| 535 } |
| 536 } |
| 537 } |
| 538 } |
| 539 |
| 540 return NULL; |
| 541 } |
| 542 |
| 543 base::DictionaryValue* FakeDriveService::FindEntryByContentUrl( |
| 544 const GURL& content_url) { |
| 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 546 |
| 547 base::DictionaryValue* resource_list_dict = NULL; |
| 548 base::ListValue* entries = NULL; |
| 549 // Go through entries and return the one that matches |content_url|. |
| 550 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 551 resource_list_dict->GetList("entry", &entries)) { |
| 552 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 553 base::DictionaryValue* entry = NULL; |
| 554 base::DictionaryValue* content = NULL; |
| 555 std::string current_content_url; |
| 556 if (entries->GetDictionary(i, &entry) && |
| 557 entry->GetDictionary("content", &content) && |
| 558 content->GetString("src", ¤t_content_url) && |
| 559 content_url == GURL(current_content_url)) { |
| 560 return entry; |
| 561 } |
| 562 } |
| 563 } |
| 564 |
| 565 return NULL; |
| 566 } |
| 567 |
| 568 std::string FakeDriveService::GetNewResourceId() { |
| 569 ++resource_id_count_; |
| 570 return base::StringPrintf("resource_id_%d", resource_id_count_); |
| 571 } |
| 572 |
284 } // namespace google_apis | 573 } // namespace google_apis |
OLD | NEW |