| 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/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/gdata.pb.h" | 24 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 25 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
| 26 #include "chrome/browser/chromeos/gdata/gdata_file_write_helper.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" |
| 34 #include "chrome/common/chrome_version_info.h" | 35 #include "chrome/common/chrome_version_info.h" |
| 35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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 GDataFileWriteHelper* GetGDataFileWriteHelper(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 Loading... |
| 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) { |
| 592 if (IsUnderGDataMountPoint(path)) { |
| 593 GDataFileWriteHelper* file_write_helper = GetGDataFileWriteHelper(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 |
| OLD | NEW |