| Index: chrome/browser/extensions/api/time/time_api.cc
|
| diff --git a/chrome/browser/extensions/api/time/time_api.cc b/chrome/browser/extensions/api/time/time_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1799e8de97570da144a2df9e3d35028a03e92bbd
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/time/time_api.cc
|
| @@ -0,0 +1,45 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/extensions/api/time/time_api.h"
|
| +
|
| +#include <time.h>
|
| +#include <string>
|
| +
|
| +namespace extensions {
|
| +
|
| +TimeGetTimeFunction::~TimeGetTimeFunction() {}
|
| +
|
| +bool TimeGetTimeFunction::RunImpl() {
|
| + // Args are passed in via the args_ member as a base::ListValue.
|
| + // Use the convenience member of the glue class to easily parse it.
|
| + scoped_ptr<api::time::GetTime::Params> params(
|
| + api::time::GetTime::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params.get());
|
| + time_t rawtime;
|
| + struct tm * timeinfo;
|
| + char buffer[80];
|
| + std::string format = "%d/%m/%Y";
|
| +
|
| + time(&rawtime);
|
| + timeinfo = localtime(&rawtime);
|
| + if (params->format) {
|
| + format = params->format->c_str();
|
| + }
|
| + std::strftime(buffer, arraysize(buffer), format.c_str(), timeinfo);
|
| +
|
| + api::time::TimeResult result;
|
| + result.time_string = buffer;
|
| +
|
| + // Use the convenience member of the glue class to easily serialize
|
| + // to base::Value. ExtensionFunction owns the resulting base::Value.
|
| + SetResult(result.ToValue().release());
|
| + // Not needed if you're a SyncExtensionFunction
|
| + // since it's set on the return value of RunImpl().
|
| + SendResponse(true /* success */);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace extensions
|
| +
|
|
|