Chromium Code Reviews| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 11 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 12 #include "chrome/browser/google_apis/test_util.h" | 12 #include "chrome/browser/google_apis/test_util.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 | 14 |
| 15 using content::BrowserThread; | 15 using content::BrowserThread; |
| 16 | 16 |
| 17 namespace google_apis { | 17 namespace google_apis { |
| 18 | 18 |
| 19 FakeDriveService::FakeDriveService() | 19 FakeDriveService::FakeDriveService() |
| 20 : resource_id_count_(0) { | 20 : resource_id_count_(0), |
| 21 offline_(false) { | |
| 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 FakeDriveService::~FakeDriveService() { | 25 FakeDriveService::~FakeDriveService() { |
| 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool FakeDriveService::LoadResourceListForWapi( | 29 bool FakeDriveService::LoadResourceListForWapi( |
| 29 const std::string& relative_path) { | 30 const std::string& relative_path) { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 void FakeDriveService::GetResourceList( | 102 void FakeDriveService::GetResourceList( |
| 102 const GURL& feed_url, | 103 const GURL& feed_url, |
| 103 int64 start_changestamp, | 104 int64 start_changestamp, |
| 104 const std::string& search_query, | 105 const std::string& search_query, |
| 105 bool shared_with_me, | 106 bool shared_with_me, |
| 106 const std::string& directory_resource_id, | 107 const std::string& directory_resource_id, |
| 107 const GetResourceListCallback& callback) { | 108 const GetResourceListCallback& callback) { |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 109 DCHECK(!callback.is_null()); | 110 DCHECK(!callback.is_null()); |
| 110 | 111 |
| 112 if (offline_) { | |
| 113 scoped_ptr<ResourceList> null; | |
| 114 MessageLoop::current()->PostTask( | |
| 115 FROM_HERE, | |
| 116 base::Bind(callback, | |
| 117 GDATA_NO_CONNECTION, | |
| 118 base::Passed(&null))); | |
| 119 return; | |
| 120 } | |
| 121 | |
| 111 scoped_ptr<ResourceList> resource_list = | 122 scoped_ptr<ResourceList> resource_list = |
| 112 ResourceList::CreateFrom(*resource_list_value_); | 123 ResourceList::CreateFrom(*resource_list_value_); |
| 113 MessageLoop::current()->PostTask( | 124 MessageLoop::current()->PostTask( |
| 114 FROM_HERE, | 125 FROM_HERE, |
| 115 base::Bind(callback, | 126 base::Bind(callback, |
| 116 HTTP_SUCCESS, | 127 HTTP_SUCCESS, |
| 117 base::Passed(&resource_list))); | 128 base::Passed(&resource_list))); |
| 118 } | 129 } |
| 119 | 130 |
| 120 void FakeDriveService::GetResourceEntry( | 131 void FakeDriveService::GetResourceEntry( |
| 121 const std::string& resource_id, | 132 const std::string& resource_id, |
| 122 const GetResourceEntryCallback& callback) { | 133 const GetResourceEntryCallback& callback) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 DCHECK(!callback.is_null()); | 135 DCHECK(!callback.is_null()); |
| 125 | 136 |
| 137 if (offline_) { | |
| 138 scoped_ptr<ResourceEntry> null; | |
| 139 MessageLoop::current()->PostTask( | |
| 140 FROM_HERE, | |
| 141 base::Bind(callback, | |
| 142 GDATA_NO_CONNECTION, | |
| 143 base::Passed(&null))); | |
| 144 return; | |
| 145 } | |
| 146 | |
| 126 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 147 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 127 if (entry) { | 148 if (entry) { |
| 128 scoped_ptr<ResourceEntry> resource_entry = | 149 scoped_ptr<ResourceEntry> resource_entry = |
| 129 ResourceEntry::CreateFrom(*entry); | 150 ResourceEntry::CreateFrom(*entry); |
| 130 MessageLoop::current()->PostTask( | 151 MessageLoop::current()->PostTask( |
| 131 FROM_HERE, | 152 FROM_HERE, |
| 132 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); | 153 base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry))); |
| 133 return; | 154 return; |
| 134 } | 155 } |
| 135 | 156 |
| 136 scoped_ptr<ResourceEntry> null; | 157 scoped_ptr<ResourceEntry> null; |
| 137 MessageLoop::current()->PostTask( | 158 MessageLoop::current()->PostTask( |
| 138 FROM_HERE, | 159 FROM_HERE, |
| 139 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | 160 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 140 } | 161 } |
| 141 | 162 |
| 142 void FakeDriveService::GetAccountMetadata( | 163 void FakeDriveService::GetAccountMetadata( |
| 143 const GetAccountMetadataCallback& callback) { | 164 const GetAccountMetadataCallback& callback) { |
| 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 145 DCHECK(!callback.is_null()); | 166 DCHECK(!callback.is_null()); |
| 146 | 167 |
| 168 if (offline_) { | |
| 169 scoped_ptr<AccountMetadataFeed> null; | |
| 170 MessageLoop::current()->PostTask( | |
| 171 FROM_HERE, | |
| 172 base::Bind(callback, | |
| 173 GDATA_NO_CONNECTION, | |
| 174 base::Passed(&null))); | |
| 175 return; | |
| 176 } | |
| 147 scoped_ptr<AccountMetadataFeed> account_metadata = | 177 scoped_ptr<AccountMetadataFeed> account_metadata = |
| 148 AccountMetadataFeed::CreateFrom(*account_metadata_value_); | 178 AccountMetadataFeed::CreateFrom(*account_metadata_value_); |
| 149 MessageLoop::current()->PostTask( | 179 MessageLoop::current()->PostTask( |
| 150 FROM_HERE, | 180 FROM_HERE, |
| 151 base::Bind(callback, | 181 base::Bind(callback, |
| 152 HTTP_SUCCESS, | 182 HTTP_SUCCESS, |
| 153 base::Passed(&account_metadata))); | 183 base::Passed(&account_metadata))); |
| 154 } | 184 } |
| 155 | 185 |
| 156 void FakeDriveService::GetApplicationInfo( | 186 void FakeDriveService::GetApplicationInfo( |
| 157 const GetDataCallback& callback) { | 187 const GetDataCallback& callback) { |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 159 DCHECK(!callback.is_null()); | 189 DCHECK(!callback.is_null()); |
| 160 | 190 |
| 191 if (offline_) { | |
| 192 scoped_ptr<base::Value> null; | |
| 193 MessageLoop::current()->PostTask( | |
| 194 FROM_HERE, | |
| 195 base::Bind(callback, | |
| 196 GDATA_NO_CONNECTION, | |
| 197 base::Passed(&null))); | |
| 198 return; | |
| 199 } | |
| 200 | |
| 161 scoped_ptr<base::Value> copied_app_info_value( | 201 scoped_ptr<base::Value> copied_app_info_value( |
| 162 app_info_value_->DeepCopy()); | 202 app_info_value_->DeepCopy()); |
| 163 MessageLoop::current()->PostTask( | 203 MessageLoop::current()->PostTask( |
| 164 FROM_HERE, | 204 FROM_HERE, |
| 165 base::Bind(callback, | 205 base::Bind(callback, |
| 166 HTTP_SUCCESS, | 206 HTTP_SUCCESS, |
| 167 base::Passed(&copied_app_info_value))); | 207 base::Passed(&copied_app_info_value))); |
| 168 | 208 |
| 169 } | 209 } |
| 170 | 210 |
| 171 void FakeDriveService::DeleteResource( | 211 void FakeDriveService::DeleteResource( |
| 172 const GURL& edit_url, | 212 const GURL& edit_url, |
| 173 const EntryActionCallback& callback) { | 213 const EntryActionCallback& callback) { |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 175 DCHECK(!callback.is_null()); | 215 DCHECK(!callback.is_null()); |
| 176 | 216 |
| 217 if (offline_) { | |
| 218 scoped_ptr<base::Value> null; | |
|
kinaba
2013/01/10 04:33:54
not used.
satorux1
2013/01/10 04:41:33
Done.
| |
| 219 MessageLoop::current()->PostTask( | |
| 220 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | |
| 221 return; | |
| 222 } | |
| 223 | |
| 177 base::DictionaryValue* resource_list_dict = NULL; | 224 base::DictionaryValue* resource_list_dict = NULL; |
| 178 base::ListValue* entries = NULL; | 225 base::ListValue* entries = NULL; |
| 179 // Go through entries and remove the one that matches |edit_url|. | 226 // Go through entries and remove the one that matches |edit_url|. |
| 180 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | 227 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 181 resource_list_dict->GetList("entry", &entries)) { | 228 resource_list_dict->GetList("entry", &entries)) { |
| 182 for (size_t i = 0; i < entries->GetSize(); ++i) { | 229 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 183 base::DictionaryValue* entry = NULL; | 230 base::DictionaryValue* entry = NULL; |
| 184 base::ListValue* links = NULL; | 231 base::ListValue* links = NULL; |
| 185 if (entries->GetDictionary(i, &entry) && | 232 if (entries->GetDictionary(i, &entry) && |
| 186 entry->GetList("link", &links)) { | 233 entry->GetList("link", &links)) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 | 266 |
| 220 void FakeDriveService::DownloadFile( | 267 void FakeDriveService::DownloadFile( |
| 221 const FilePath& virtual_path, | 268 const FilePath& virtual_path, |
| 222 const FilePath& local_cache_path, | 269 const FilePath& local_cache_path, |
| 223 const GURL& content_url, | 270 const GURL& content_url, |
| 224 const DownloadActionCallback& download_action_callback, | 271 const DownloadActionCallback& download_action_callback, |
| 225 const GetContentCallback& get_content_callback) { | 272 const GetContentCallback& get_content_callback) { |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 DCHECK(!download_action_callback.is_null()); | 274 DCHECK(!download_action_callback.is_null()); |
| 228 | 275 |
| 276 if (offline_) { | |
| 277 scoped_ptr<base::Value> null; | |
|
kinaba
2013/01/10 04:33:54
ditto.
satorux1
2013/01/10 04:41:33
Done.
| |
| 278 MessageLoop::current()->PostTask( | |
| 279 FROM_HERE, | |
| 280 base::Bind(download_action_callback, | |
| 281 GDATA_NO_CONNECTION, | |
| 282 FilePath())); | |
| 283 return; | |
| 284 } | |
| 285 | |
| 229 base::DictionaryValue* entry = FindEntryByContentUrl(content_url); | 286 base::DictionaryValue* entry = FindEntryByContentUrl(content_url); |
| 230 if (!entry) { | 287 if (!entry) { |
| 231 base::MessageLoopProxy::current()->PostTask( | 288 base::MessageLoopProxy::current()->PostTask( |
| 232 FROM_HERE, | 289 FROM_HERE, |
| 233 base::Bind(download_action_callback, HTTP_NOT_FOUND, FilePath())); | 290 base::Bind(download_action_callback, HTTP_NOT_FOUND, FilePath())); |
| 234 return; | 291 return; |
| 235 } | 292 } |
| 236 | 293 |
| 237 // Write the content URL as the content of the file. | 294 // Write the content URL as the content of the file. |
| 238 if (static_cast<int>(content_url.spec().size()) != | 295 if (static_cast<int>(content_url.spec().size()) != |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 250 base::Bind(download_action_callback, HTTP_SUCCESS, local_cache_path)); | 307 base::Bind(download_action_callback, HTTP_SUCCESS, local_cache_path)); |
| 251 } | 308 } |
| 252 | 309 |
| 253 void FakeDriveService::CopyHostedDocument( | 310 void FakeDriveService::CopyHostedDocument( |
| 254 const std::string& resource_id, | 311 const std::string& resource_id, |
| 255 const FilePath::StringType& new_name, | 312 const FilePath::StringType& new_name, |
| 256 const GetResourceEntryCallback& callback) { | 313 const GetResourceEntryCallback& callback) { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 258 DCHECK(!callback.is_null()); | 315 DCHECK(!callback.is_null()); |
| 259 | 316 |
| 317 if (offline_) { | |
| 318 scoped_ptr<ResourceEntry> null; | |
| 319 MessageLoop::current()->PostTask( | |
| 320 FROM_HERE, | |
| 321 base::Bind(callback, | |
| 322 GDATA_NO_CONNECTION, | |
| 323 base::Passed(&null))); | |
| 324 return; | |
| 325 } | |
| 326 | |
| 260 base::DictionaryValue* resource_list_dict = NULL; | 327 base::DictionaryValue* resource_list_dict = NULL; |
| 261 base::ListValue* entries = NULL; | 328 base::ListValue* entries = NULL; |
| 262 // Go through entries and copy the one that matches |resource_id|. | 329 // Go through entries and copy the one that matches |resource_id|. |
| 263 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && | 330 if (resource_list_value_->GetAsDictionary(&resource_list_dict) && |
| 264 resource_list_dict->GetList("entry", &entries)) { | 331 resource_list_dict->GetList("entry", &entries)) { |
| 265 for (size_t i = 0; i < entries->GetSize(); ++i) { | 332 for (size_t i = 0; i < entries->GetSize(); ++i) { |
| 266 base::DictionaryValue* entry = NULL; | 333 base::DictionaryValue* entry = NULL; |
| 267 base::DictionaryValue* resource_id_dict = NULL; | 334 base::DictionaryValue* resource_id_dict = NULL; |
| 268 base::ListValue* categories = NULL; | 335 base::ListValue* categories = NULL; |
| 269 std::string current_resource_id; | 336 std::string current_resource_id; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | 380 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 314 } | 381 } |
| 315 | 382 |
| 316 void FakeDriveService::RenameResource( | 383 void FakeDriveService::RenameResource( |
| 317 const GURL& edit_url, | 384 const GURL& edit_url, |
| 318 const FilePath::StringType& new_name, | 385 const FilePath::StringType& new_name, |
| 319 const EntryActionCallback& callback) { | 386 const EntryActionCallback& callback) { |
| 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 321 DCHECK(!callback.is_null()); | 388 DCHECK(!callback.is_null()); |
| 322 | 389 |
| 390 if (offline_) { | |
| 391 scoped_ptr<ResourceEntry> null; | |
|
kinaba
2013/01/10 04:33:54
ditto.
satorux1
2013/01/10 04:41:33
Done.
| |
| 392 MessageLoop::current()->PostTask( | |
| 393 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | |
| 394 return; | |
| 395 } | |
| 396 | |
| 323 base::DictionaryValue* entry = FindEntryByEditUrl(edit_url); | 397 base::DictionaryValue* entry = FindEntryByEditUrl(edit_url); |
| 324 if (entry) { | 398 if (entry) { |
| 325 entry->SetString("title.$t", | 399 entry->SetString("title.$t", |
| 326 FilePath(new_name).AsUTF8Unsafe()); | 400 FilePath(new_name).AsUTF8Unsafe()); |
| 327 MessageLoop::current()->PostTask( | 401 MessageLoop::current()->PostTask( |
| 328 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); | 402 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); |
| 329 return; | 403 return; |
| 330 } | 404 } |
| 331 | 405 |
| 332 MessageLoop::current()->PostTask( | 406 MessageLoop::current()->PostTask( |
| 333 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 407 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
| 334 } | 408 } |
| 335 | 409 |
| 336 void FakeDriveService::AddResourceToDirectory( | 410 void FakeDriveService::AddResourceToDirectory( |
| 337 const GURL& parent_content_url, | 411 const GURL& parent_content_url, |
| 338 const GURL& edit_url, | 412 const GURL& edit_url, |
| 339 const EntryActionCallback& callback) { | 413 const EntryActionCallback& callback) { |
| 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 341 DCHECK(!callback.is_null()); | 415 DCHECK(!callback.is_null()); |
| 342 | 416 |
| 417 if (offline_) { | |
| 418 scoped_ptr<ResourceEntry> null; | |
|
kinaba
2013/01/10 04:33:54
ditto.
satorux1
2013/01/10 04:41:33
Done.
| |
| 419 MessageLoop::current()->PostTask( | |
| 420 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | |
| 421 return; | |
| 422 } | |
| 423 | |
| 343 base::DictionaryValue* entry = FindEntryByEditUrl(edit_url); | 424 base::DictionaryValue* entry = FindEntryByEditUrl(edit_url); |
| 344 if (entry) { | 425 if (entry) { |
| 345 base::ListValue* links = NULL; | 426 base::ListValue* links = NULL; |
| 346 if (entry->GetList("link", &links)) { | 427 if (entry->GetList("link", &links)) { |
| 347 bool parent_link_found = false; | 428 bool parent_link_found = false; |
| 348 for (size_t i = 0; i < links->GetSize(); ++i) { | 429 for (size_t i = 0; i < links->GetSize(); ++i) { |
| 349 base::DictionaryValue* link = NULL; | 430 base::DictionaryValue* link = NULL; |
| 350 std::string rel; | 431 std::string rel; |
| 351 if (links->GetDictionary(i, &link) && | 432 if (links->GetDictionary(i, &link) && |
| 352 link->GetString("rel", &rel) && | 433 link->GetString("rel", &rel) && |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 374 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 455 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
| 375 } | 456 } |
| 376 | 457 |
| 377 void FakeDriveService::RemoveResourceFromDirectory( | 458 void FakeDriveService::RemoveResourceFromDirectory( |
| 378 const GURL& parent_content_url, | 459 const GURL& parent_content_url, |
| 379 const std::string& resource_id, | 460 const std::string& resource_id, |
| 380 const EntryActionCallback& callback) { | 461 const EntryActionCallback& callback) { |
| 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 382 DCHECK(!callback.is_null()); | 463 DCHECK(!callback.is_null()); |
| 383 | 464 |
| 465 if (offline_) { | |
| 466 scoped_ptr<ResourceEntry> null; | |
|
kinaba
2013/01/10 04:33:54
ditto.
satorux1
2013/01/10 04:41:33
Done.
| |
| 467 MessageLoop::current()->PostTask( | |
| 468 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); | |
| 469 return; | |
| 470 } | |
| 471 | |
| 384 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); | 472 base::DictionaryValue* entry = FindEntryByResourceId(resource_id); |
| 385 if (entry) { | 473 if (entry) { |
| 386 base::ListValue* links = NULL; | 474 base::ListValue* links = NULL; |
| 387 if (entry->GetList("link", &links)) { | 475 if (entry->GetList("link", &links)) { |
| 388 for (size_t i = 0; i < links->GetSize(); ++i) { | 476 for (size_t i = 0; i < links->GetSize(); ++i) { |
| 389 base::DictionaryValue* link = NULL; | 477 base::DictionaryValue* link = NULL; |
| 390 std::string rel; | 478 std::string rel; |
| 391 std::string href; | 479 std::string href; |
| 392 if (links->GetDictionary(i, &link) && | 480 if (links->GetDictionary(i, &link) && |
| 393 link->GetString("rel", &rel) && | 481 link->GetString("rel", &rel) && |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 407 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 495 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
| 408 } | 496 } |
| 409 | 497 |
| 410 void FakeDriveService::AddNewDirectory( | 498 void FakeDriveService::AddNewDirectory( |
| 411 const GURL& parent_content_url, | 499 const GURL& parent_content_url, |
| 412 const FilePath::StringType& directory_name, | 500 const FilePath::StringType& directory_name, |
| 413 const GetResourceEntryCallback& callback) { | 501 const GetResourceEntryCallback& callback) { |
| 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 415 DCHECK(!callback.is_null()); | 503 DCHECK(!callback.is_null()); |
| 416 | 504 |
| 505 if (offline_) { | |
| 506 scoped_ptr<ResourceEntry> null; | |
| 507 MessageLoop::current()->PostTask( | |
| 508 FROM_HERE, | |
| 509 base::Bind(callback, | |
| 510 GDATA_NO_CONNECTION, | |
| 511 base::Passed(&null))); | |
| 512 return; | |
| 513 } | |
| 514 | |
| 417 // If the parent content URL is not empty, the parent should exist. | 515 // If the parent content URL is not empty, the parent should exist. |
| 418 if (!parent_content_url.is_empty()) { | 516 if (!parent_content_url.is_empty()) { |
| 419 base::DictionaryValue* parent_entry = | 517 base::DictionaryValue* parent_entry = |
| 420 FindEntryByContentUrl(parent_content_url); | 518 FindEntryByContentUrl(parent_content_url); |
| 421 if (!parent_entry) { | 519 if (!parent_entry) { |
| 422 scoped_ptr<ResourceEntry> null; | 520 scoped_ptr<ResourceEntry> null; |
| 423 MessageLoop::current()->PostTask( | 521 MessageLoop::current()->PostTask( |
| 424 FROM_HERE, | 522 FROM_HERE, |
| 425 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | 523 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 426 return; | 524 return; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 content_url == GURL(current_content_url)) { | 681 content_url == GURL(current_content_url)) { |
| 584 return entry; | 682 return entry; |
| 585 } | 683 } |
| 586 } | 684 } |
| 587 } | 685 } |
| 588 | 686 |
| 589 return NULL; | 687 return NULL; |
| 590 } | 688 } |
| 591 | 689 |
| 592 std::string FakeDriveService::GetNewResourceId() { | 690 std::string FakeDriveService::GetNewResourceId() { |
| 691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 692 | |
| 593 ++resource_id_count_; | 693 ++resource_id_count_; |
| 594 return base::StringPrintf("resource_id_%d", resource_id_count_); | 694 return base::StringPrintf("resource_id_%d", resource_id_count_); |
| 595 } | 695 } |
| 596 | 696 |
| 597 } // namespace google_apis | 697 } // namespace google_apis |
| OLD | NEW |