| 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_GOOGLE_APIS_GDATA_UTIL_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_GDATA_UTIL_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_UTIL_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/string_piece.h" |
| 11 #include "base/logging.h" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/task_runner_util.h" | |
| 14 #include "chrome/browser/google_apis/gdata_errorcode.h" | |
| 15 | 11 |
| 16 class FilePath; | 12 class FilePath; |
| 17 class Profile; | 13 class Profile; |
| 18 | 14 |
| 19 namespace base { | 15 namespace base { |
| 20 class SequencedTaskRunner; | |
| 21 class Time; | 16 class Time; |
| 22 } // namespace base | 17 } // namespace base |
| 23 | 18 |
| 24 namespace tracked_objects { | |
| 25 class Location; | |
| 26 } // tracked_objects | |
| 27 | |
| 28 namespace google_apis { | 19 namespace google_apis { |
| 29 namespace util { | 20 namespace util { |
| 30 | 21 |
| 31 // Returns true if Drive v2 API is enabled via commandline switch. | 22 // Returns true if Drive v2 API is enabled via commandline switch. |
| 32 bool IsDriveV2ApiEnabled(); | 23 bool IsDriveV2ApiEnabled(); |
| 33 | 24 |
| 34 // Parses an RFC 3339 date/time into a base::Time, returning true on success. | 25 // Parses an RFC 3339 date/time into a base::Time, returning true on success. |
| 35 // The time string must be in the format "yyyy-mm-ddThh:mm:ss.dddTZ" (TZ is | 26 // The time string must be in the format "yyyy-mm-ddThh:mm:ss.dddTZ" (TZ is |
| 36 // either '+hh:mm', '-hh:mm', 'Z' (representing UTC), or an empty string). | 27 // either '+hh:mm', '-hh:mm', 'Z' (representing UTC), or an empty string). |
| 37 bool GetTimeFromString(const base::StringPiece& raw_value, base::Time* time); | 28 bool GetTimeFromString(const base::StringPiece& raw_value, base::Time* time); |
| 38 | 29 |
| 39 // Formats a base::Time as an RFC 3339 date/time (in UTC). | 30 // Formats a base::Time as an RFC 3339 date/time (in UTC). |
| 40 std::string FormatTimeAsString(const base::Time& time); | 31 std::string FormatTimeAsString(const base::Time& time); |
| 41 // Formats a base::Time as an RFC 3339 date/time (in localtime). | 32 // Formats a base::Time as an RFC 3339 date/time (in localtime). |
| 42 std::string FormatTimeAsStringLocaltime(const base::Time& time); | 33 std::string FormatTimeAsStringLocaltime(const base::Time& time); |
| 43 | 34 |
| 44 // Wrapper around BrowserThread::PostTask to post a task to the blocking | |
| 45 // pool with the given sequence token. | |
| 46 void PostBlockingPoolSequencedTask( | |
| 47 const tracked_objects::Location& from_here, | |
| 48 base::SequencedTaskRunner* blocking_task_runner, | |
| 49 const base::Closure& task); | |
| 50 | |
| 51 // Similar to PostBlockingPoolSequencedTask() but this one takes a reply | |
| 52 // callback that runs on the calling thread. | |
| 53 void PostBlockingPoolSequencedTaskAndReply( | |
| 54 const tracked_objects::Location& from_here, | |
| 55 base::SequencedTaskRunner* blocking_task_runner, | |
| 56 const base::Closure& request_task, | |
| 57 const base::Closure& reply_task); | |
| 58 | |
| 59 // Similar to PostBlockingPoolSequencedTaskAndReply() but this one runs the | |
| 60 // reply callback with the return value of the request task. | |
| 61 template <typename ReturnType> | |
| 62 void PostBlockingPoolSequencedTaskAndReplyWithResult( | |
| 63 const tracked_objects::Location& from_here, | |
| 64 base::SequencedTaskRunner* blocking_task_runner, | |
| 65 const base::Callback<ReturnType(void)>& request_task, | |
| 66 const base::Callback<void(ReturnType)>& reply_task) { | |
| 67 const bool posted = base::PostTaskAndReplyWithResult(blocking_task_runner, | |
| 68 from_here, | |
| 69 request_task, | |
| 70 reply_task); | |
| 71 DCHECK(posted); | |
| 72 } | |
| 73 | |
| 74 } // namespace util | 35 } // namespace util |
| 75 } // namespace google_apis | 36 } // namespace google_apis |
| 76 | 37 |
| 77 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_UTIL_H_ | 38 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_UTIL_H_ |
| OLD | NEW |