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

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

Issue 11824020: google_apis: Implement DownloadFile in FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add DownloadFile_NonexistingFile test Created 7 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/google_apis/fake_drive_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/logging.h" 8 #include "base/logging.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
10 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 11 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
11 #include "chrome/browser/google_apis/test_util.h" 12 #include "chrome/browser/google_apis/test_util.h"
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 14
14 using content::BrowserThread; 15 using content::BrowserThread;
15 16
16 namespace google_apis { 17 namespace google_apis {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 218 }
218 219
219 void FakeDriveService::DownloadFile( 220 void FakeDriveService::DownloadFile(
220 const FilePath& virtual_path, 221 const FilePath& virtual_path,
221 const FilePath& local_cache_path, 222 const FilePath& local_cache_path,
222 const GURL& content_url, 223 const GURL& content_url,
223 const DownloadActionCallback& download_action_callback, 224 const DownloadActionCallback& download_action_callback,
224 const GetContentCallback& get_content_callback) { 225 const GetContentCallback& get_content_callback) {
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
226 DCHECK(!download_action_callback.is_null()); 227 DCHECK(!download_action_callback.is_null());
228
229 base::DictionaryValue* entry = FindEntryByContentUrl(content_url);
230 if (!entry) {
231 base::MessageLoopProxy::current()->PostTask(
232 FROM_HERE,
233 base::Bind(download_action_callback, HTTP_NOT_FOUND, FilePath()));
234 return;
235 }
236
237 // Write the content URL as the content of the file.
238 if (static_cast<int>(content_url.spec().size()) !=
239 file_util::WriteFile(local_cache_path,
240 content_url.spec().data(),
241 content_url.spec().size())) {
242 base::MessageLoopProxy::current()->PostTask(
243 FROM_HERE,
244 base::Bind(download_action_callback, GDATA_FILE_ERROR, FilePath()));
245 return;
246 }
247
248 base::MessageLoopProxy::current()->PostTask(
249 FROM_HERE,
250 base::Bind(download_action_callback, HTTP_SUCCESS, local_cache_path));
227 } 251 }
228 252
229 void FakeDriveService::CopyHostedDocument( 253 void FakeDriveService::CopyHostedDocument(
230 const std::string& resource_id, 254 const std::string& resource_id,
231 const FilePath::StringType& new_name, 255 const FilePath::StringType& new_name,
232 const GetResourceEntryCallback& callback) { 256 const GetResourceEntryCallback& callback) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 DCHECK(!callback.is_null()); 258 DCHECK(!callback.is_null());
235 259
236 base::DictionaryValue* resource_list_dict = NULL; 260 base::DictionaryValue* resource_list_dict = NULL;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 588
565 return NULL; 589 return NULL;
566 } 590 }
567 591
568 std::string FakeDriveService::GetNewResourceId() { 592 std::string FakeDriveService::GetNewResourceId() {
569 ++resource_id_count_; 593 ++resource_id_count_;
570 return base::StringPrintf("resource_id_%d", resource_id_count_); 594 return base::StringPrintf("resource_id_%d", resource_id_count_);
571 } 595 }
572 596
573 } // namespace google_apis 597 } // namespace google_apis
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/fake_drive_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698