Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/extensions/api/time/time_api.cc

Issue 18063003: Chromium extension API - written as part of course in Open Software Development at Reykjavik Univer… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Second round of fixes from review Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/time/time_api.h ('k') | chrome/browser/extensions/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698