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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UTIL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 | 17 |
18 class FilePath; | 18 class FilePath; |
19 class Profile; | 19 class Profile; |
20 | 20 |
| 21 namespace base { |
| 22 class SequencedTaskRunner; |
| 23 } // namespace base |
| 24 |
| 25 namespace tracked_objects { |
| 26 class Location; |
| 27 } // tracked_objects |
| 28 |
21 namespace gdata { | 29 namespace gdata { |
22 namespace util { | 30 namespace util { |
23 | 31 |
24 // Path constants. | 32 // Path constants. |
25 | 33 |
26 // The extension for dirty files. The file names look like | 34 // The extension for dirty files. The file names look like |
27 // "<resource-id>.local". | 35 // "<resource-id>.local". |
28 const char kLocallyModifiedFileExtension[] = "local"; | 36 const char kLocallyModifiedFileExtension[] = "local"; |
29 // The extension for mounted files. The file names look like | 37 // The extension for mounted files. The file names look like |
30 // "<resource-id>.<md5>.mounted". | 38 // "<resource-id>.<md5>.mounted". |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Parses an RFC 3339 date/time into a base::Time, returning true on success. | 113 // Parses an RFC 3339 date/time into a base::Time, returning true on success. |
106 // The time string must be in the format "yyyy-mm-ddThh:mm:ss.dddTZ" (TZ is | 114 // The time string must be in the format "yyyy-mm-ddThh:mm:ss.dddTZ" (TZ is |
107 // either '+hh:mm', '-hh:mm', 'Z' (representing UTC), or an empty string). | 115 // either '+hh:mm', '-hh:mm', 'Z' (representing UTC), or an empty string). |
108 bool GetTimeFromString(const base::StringPiece& raw_value, base::Time* time); | 116 bool GetTimeFromString(const base::StringPiece& raw_value, base::Time* time); |
109 | 117 |
110 // Formats a base::Time as an RFC 3339 date/time (in UTC). | 118 // Formats a base::Time as an RFC 3339 date/time (in UTC). |
111 std::string FormatTimeAsString(const base::Time& time); | 119 std::string FormatTimeAsString(const base::Time& time); |
112 | 120 |
113 // Callback type for PrepareWritableFilePathAndRun. | 121 // Callback type for PrepareWritableFilePathAndRun. |
114 typedef base::Callback<void (GDataFileError, const FilePath& path)> | 122 typedef base::Callback<void (GDataFileError, const FilePath& path)> |
115 OpenFileCallback; | 123 OpenFileCallback; |
116 | 124 |
117 // Invokes |callback| on blocking thread pool, after converting virtual |path| | 125 // Invokes |callback| on blocking thread pool, after converting virtual |path| |
118 // string like "/special/drive/foo.txt" to the concrete local cache file path. | 126 // string like "/special/drive/foo.txt" to the concrete local cache file path. |
119 // After |callback| returns, the written content is synchronized to the server. | 127 // After |callback| returns, the written content is synchronized to the server. |
120 // | 128 // |
121 // If |path| is not a GData path, it is regarded as a local path and no path | 129 // If |path| is not a GData path, it is regarded as a local path and no path |
122 // conversion takes place. | 130 // conversion takes place. |
123 // | 131 // |
124 // Must be called from UI thread. | 132 // Must be called from UI thread. |
125 void PrepareWritableFileAndRun(Profile* profile, | 133 void PrepareWritableFileAndRun(Profile* profile, |
126 const FilePath& path, | 134 const FilePath& path, |
127 const OpenFileCallback& callback); | 135 const OpenFileCallback& callback); |
128 | 136 |
| 137 // Converts gdata error code into file platform error code. |
| 138 GDataFileError GDataToGDataFileError(GDataErrorCode status); |
| 139 |
| 140 // Wrapper around BrowserThread::PostTask to post a task to the blocking |
| 141 // pool with the given sequence token. |
| 142 void PostBlockingPoolSequencedTask( |
| 143 const tracked_objects::Location& from_here, |
| 144 base::SequencedTaskRunner* blocking_task_runner, |
| 145 const base::Closure& task); |
| 146 |
| 147 // Similar to PostBlockingPoolSequencedTask() but this one takes a reply |
| 148 // callback that runs on the calling thread. |
| 149 void PostBlockingPoolSequencedTaskAndReply( |
| 150 const tracked_objects::Location& from_here, |
| 151 base::SequencedTaskRunner* blocking_task_runner, |
| 152 const base::Closure& request_task, |
| 153 const base::Closure& reply_task); |
| 154 |
129 } // namespace util | 155 } // namespace util |
130 } // namespace gdata | 156 } // namespace gdata |
131 | 157 |
132 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UTIL_H_ | 158 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_UTIL_H_ |
OLD | NEW |