OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/time/time_api.h" |
| 6 |
| 7 #include <time.h> |
| 8 #include <string> |
| 9 |
| 10 namespace extensions { |
| 11 |
| 12 TimeGetTimeFunction::~TimeGetTimeFunction() {} |
| 13 |
| 14 bool TimeGetTimeFunction::RunImpl() { |
| 15 // Args are passed in via the args_ member as a base::ListValue. |
| 16 // Use the convenience member of the glue class to easily parse it. |
| 17 scoped_ptr<api::time::GetTime::Params> params( |
| 18 api::time::GetTime::Params::Create(*args_)); |
| 19 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 20 time_t rawtime; |
| 21 struct tm * timeinfo; |
| 22 char buffer[80]; |
| 23 std::string format = "%d/%m/%Y"; |
| 24 |
| 25 time(&rawtime); |
| 26 timeinfo = localtime(&rawtime); |
| 27 if (params->format) { |
| 28 format = params->format->c_str(); |
| 29 } |
| 30 std::strftime(buffer, arraysize(buffer), format.c_str(), timeinfo); |
| 31 |
| 32 api::time::TimeResult result; |
| 33 result.time_string = buffer; |
| 34 |
| 35 // Use the convenience member of the glue class to easily serialize |
| 36 // to base::Value. ExtensionFunction owns the resulting base::Value. |
| 37 SetResult(result.ToValue().release()); |
| 38 // Not needed if you're a SyncExtensionFunction |
| 39 // since it's set on the return value of RunImpl(). |
| 40 SendResponse(true /* success */); |
| 41 return true; |
| 42 } |
| 43 |
| 44 } // namespace extensions |
| 45 |
OLD | NEW |