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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_util.cc

Issue 10827068: gdata: Fix "save as pdf" to work on Google Drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename again, stick to UI thread. Created 8 years, 4 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
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/chromeos/gdata/gdata_util.h" 5 #include "chrome/browser/chromeos/gdata/gdata_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/stringprintf.h" 21 #include "base/stringprintf.h"
22 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/time.h" 23 #include "base/time.h"
24 #include "chrome/browser/chromeos/gdata/file_write_helper.h"
24 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 25 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
25 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" 26 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h"
26 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 27 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
27 #include "chrome/browser/chromeos/login/user.h" 28 #include "chrome/browser/chromeos/login/user.h"
28 #include "chrome/browser/chromeos/login/user_manager.h" 29 #include "chrome/browser/chromeos/login/user_manager.h"
29 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_finder.h" 33 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
(...skipping 30 matching lines...) Expand all
64 GDataSystemServiceFactory::GetForProfile(profile); 65 GDataSystemServiceFactory::GetForProfile(profile);
65 return system_service ? system_service->file_system() : NULL; 66 return system_service ? system_service->file_system() : NULL;
66 } 67 }
67 68
68 GDataCache* GetGDataCache(Profile* profile) { 69 GDataCache* GetGDataCache(Profile* profile) {
69 GDataSystemService* system_service = 70 GDataSystemService* system_service =
70 GDataSystemServiceFactory::GetForProfile(profile); 71 GDataSystemServiceFactory::GetForProfile(profile);
71 return system_service ? system_service->cache() : NULL; 72 return system_service ? system_service->cache() : NULL;
72 } 73 }
73 74
75 FileWriteHelper* GetFileWriteHelper(Profile* profile) {
76 GDataSystemService* system_service =
77 GDataSystemServiceFactory::GetForProfile(profile);
78 return system_service ? system_service->file_write_helper() : NULL;
79 }
80
74 void GetHostedDocumentURLBlockingThread(const FilePath& gdata_cache_path, 81 void GetHostedDocumentURLBlockingThread(const FilePath& gdata_cache_path,
75 GURL* url) { 82 GURL* url) {
76 std::string json; 83 std::string json;
77 if (!file_util::ReadFileToString(gdata_cache_path, &json)) { 84 if (!file_util::ReadFileToString(gdata_cache_path, &json)) {
78 NOTREACHED() << "Unable to read file " << gdata_cache_path.value(); 85 NOTREACHED() << "Unable to read file " << gdata_cache_path.value();
79 return; 86 return;
80 } 87 }
81 DVLOG(1) << "Hosted doc content " << json; 88 DVLOG(1) << "Hosted doc content " << json;
82 scoped_ptr<base::Value> val(base::JSONReader::Read(json)); 89 scoped_ptr<base::Value> val(base::JSONReader::Read(json));
83 base::DictionaryValue* dict_val; 90 base::DictionaryValue* dict_val;
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 579
573 std::string FormatTimeAsString(const base::Time& time) { 580 std::string FormatTimeAsString(const base::Time& time) {
574 base::Time::Exploded exploded; 581 base::Time::Exploded exploded;
575 time.UTCExplode(&exploded); 582 time.UTCExplode(&exploded);
576 return base::StringPrintf( 583 return base::StringPrintf(
577 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 584 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
578 exploded.year, exploded.month, exploded.day_of_month, 585 exploded.year, exploded.month, exploded.day_of_month,
579 exploded.hour, exploded.minute, exploded.second, exploded.millisecond); 586 exploded.hour, exploded.minute, exploded.second, exploded.millisecond);
580 } 587 }
581 588
589 void PrepareWritableFileAndRun(Profile* profile,
590 const FilePath& path,
591 const OpenFileCallback& callback) {
satorux1 2012/08/02 07:37:51 Add DCHECK(BrowserThread::CurrentlyOn(BrowserThrea
kinaba 2012/08/02 08:30:02 Done.
592 if (IsUnderGDataMountPoint(path)) {
593 FileWriteHelper* file_write_helper = GetFileWriteHelper(profile);
594 if (!file_write_helper)
595 return;
596 FilePath remote_path(ExtractGDataPath(path));
597 file_write_helper->PrepareWritableFileAndRun(remote_path, callback);
598 } else {
599 if (!callback.is_null()) {
600 content::BrowserThread::GetBlockingPool()->PostTask(
601 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, path));
602 }
603 }
604 }
605
582 } // namespace util 606 } // namespace util
583 } // namespace gdata 607 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698