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