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

Side by Side Diff: chrome/browser/extensions/api/myapi/myapi_api.h

Issue 17679004: testing adding an extension api Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 6 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 #include "chrome/common/extensions/api/myapi.h"
2 #include "base/compiler_specific.h"
3 #include "base/memory/ref_counted.h"
4 #include "chrome/browser/extensions/event_router.h"
5 #include "chrome/browser/extensions/extension_function.h"
6 #include <stdlib.h> /* strtol */
7 #include "base/strings/string_number_conversions.h"
8 #include "base/memory/singleton.h"
9 #include "base/values.h"
10 #include <string>
11 #include "base/bind.h"
12 #include "base/files/file_path.h"
13 #include "base/format_macros.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/posix/eintr_wrapper.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h"
19 #include "base/threading/sequenced_worker_pool.h"
20 #include "base/time.h"
21 #include "base/values.h"
22 // You must follow a naming convention which is ApiNameFunctionNameFunction,
23 // in this case MyapiDoBazFunction. This is so that the generated code
24 // can find your implementation.
25
26 namespace extensions {
27
28 class MyapiDoBazFunction : public AsyncExtensionFunction {
29 public:
30 virtual ~MyapiDoBazFunction () {}
31
32 private:
33 // The MYAPI_DOBAZ entry is an enum you add right before ENUM_BOUNDARY
34 // in chrome/browser/extensions/extension_function_histogram_value.h
35 DECLARE_EXTENSION_FUNCTION("myapi.doBaz", MYAPI_DOBAZ);
36
37 virtual bool RunImpl() OVERRIDE {
38 // Args are passed in via the args_ member as a base::ListValue.
39 // Use the convenience member of the glue class to easily parse it.
40 scoped_ptr<api::myapi::DoBaz::Params> params(
41 api::myapi::DoBaz::Params::Create(*args_));
42 EXTENSION_FUNCTION_VALIDATE(params.get());
43
44 api::myapi::BazResult result;
45 result.x = params->options.id;
46 base::StringToInt(params->options.s, &result.y);
47
48 // Use the convenience member of the glue class to easily serialize
49 // to base::Value. ExtensionFunction owns the resulting base::Value.
50 SetResult(api::myapi::DoBaz::Results::Create(result));
51 // Not needed if you're a SyncExtensionFunction
52 // since it's set on the return value of RunImpl().
53 SendResponse(true /* success */);
54 return true;
55 }
56 };
57
58 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/myapi/myapi.cc ('k') | chrome/browser/extensions/api/myapi/myapi_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698