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

Side by Side Diff: extensions/browser/extension_function.h

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
11 #include <memory>
11 #include <string> 12 #include <string>
12 13
13 #include "base/callback.h" 14 #include "base/callback.h"
14 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/process/process.h" 19 #include "base/process/process.h"
20 #include "base/sequenced_task_runner_helpers.h" 20 #include "base/sequenced_task_runner_helpers.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/common/console_message_level.h" 22 #include "content/public/common/console_message_level.h"
23 #include "extensions/browser/extension_function_histogram_value.h" 23 #include "extensions/browser/extension_function_histogram_value.h"
24 #include "extensions/browser/info_map.h" 24 #include "extensions/browser/info_map.h"
25 #include "extensions/common/extension.h" 25 #include "extensions/common/extension.h"
26 #include "extensions/common/features/feature.h" 26 #include "extensions/common/features/feature.h"
27 #include "ipc/ipc_message.h" 27 #include "ipc/ipc_message.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // 127 //
128 // Use NoArguments(), OneArgument(), ArgumentList(), or Error() 128 // Use NoArguments(), OneArgument(), ArgumentList(), or Error()
129 // rather than this class directly. 129 // rather than this class directly.
130 class ResponseValueObject { 130 class ResponseValueObject {
131 public: 131 public:
132 virtual ~ResponseValueObject() {} 132 virtual ~ResponseValueObject() {}
133 133
134 // Returns true for success, false for failure. 134 // Returns true for success, false for failure.
135 virtual bool Apply() = 0; 135 virtual bool Apply() = 0;
136 }; 136 };
137 typedef scoped_ptr<ResponseValueObject> ResponseValue; 137 typedef std::unique_ptr<ResponseValueObject> ResponseValue;
138 138
139 // The action to use when returning from RunAsync. 139 // The action to use when returning from RunAsync.
140 // 140 //
141 // Use RespondNow() or RespondLater() rather than this class directly. 141 // Use RespondNow() or RespondLater() rather than this class directly.
142 class ResponseActionObject { 142 class ResponseActionObject {
143 public: 143 public:
144 virtual ~ResponseActionObject() {} 144 virtual ~ResponseActionObject() {}
145 145
146 virtual void Execute() = 0; 146 virtual void Execute() = 0;
147 }; 147 };
148 typedef scoped_ptr<ResponseActionObject> ResponseAction; 148 typedef std::unique_ptr<ResponseActionObject> ResponseAction;
149 149
150 // Helper class for tests to force all ExtensionFunction::user_gesture() 150 // Helper class for tests to force all ExtensionFunction::user_gesture()
151 // calls to return true as long as at least one instance of this class 151 // calls to return true as long as at least one instance of this class
152 // exists. 152 // exists.
153 class ScopedUserGestureForTests { 153 class ScopedUserGestureForTests {
154 public: 154 public:
155 ScopedUserGestureForTests(); 155 ScopedUserGestureForTests();
156 ~ScopedUserGestureForTests(); 156 ~ScopedUserGestureForTests();
157 }; 157 };
158 158
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 extensions::QuotaLimitHeuristics* heuristics) const {} 196 extensions::QuotaLimitHeuristics* heuristics) const {}
197 197
198 // Called when the quota limit has been exceeded. The default implementation 198 // Called when the quota limit has been exceeded. The default implementation
199 // returns an error. 199 // returns an error.
200 virtual void OnQuotaExceeded(const std::string& violation_error); 200 virtual void OnQuotaExceeded(const std::string& violation_error);
201 201
202 // Specifies the raw arguments to the function, as a JSON value. 202 // Specifies the raw arguments to the function, as a JSON value.
203 virtual void SetArgs(const base::ListValue* args); 203 virtual void SetArgs(const base::ListValue* args);
204 204
205 // Sets a single Value as the results of the function. 205 // Sets a single Value as the results of the function.
206 void SetResult(scoped_ptr<base::Value> result); 206 void SetResult(std::unique_ptr<base::Value> result);
207 // As above, but deprecated. TODO(estade): remove. 207 // As above, but deprecated. TODO(estade): remove.
208 void SetResult(base::Value* result); 208 void SetResult(base::Value* result);
209 209
210 // Sets multiple Values as the results of the function. 210 // Sets multiple Values as the results of the function.
211 void SetResultList(scoped_ptr<base::ListValue> results); 211 void SetResultList(std::unique_ptr<base::ListValue> results);
212 212
213 // Retrieves the results of the function as a ListValue. 213 // Retrieves the results of the function as a ListValue.
214 const base::ListValue* GetResultList() const; 214 const base::ListValue* GetResultList() const;
215 215
216 // Retrieves any error string from the function. 216 // Retrieves any error string from the function.
217 virtual std::string GetError() const; 217 virtual std::string GetError() const;
218 218
219 // Sets the function's error string. 219 // Sets the function's error string.
220 virtual void SetError(const std::string& error); 220 virtual void SetError(const std::string& error);
221 221
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 293
294 // ResponseValues. 294 // ResponseValues.
295 // 295 //
296 // Success, no arguments to pass to caller. 296 // Success, no arguments to pass to caller.
297 ResponseValue NoArguments(); 297 ResponseValue NoArguments();
298 // Success, a single argument |arg| to pass to caller. TAKES OWNERSHIP - a 298 // Success, a single argument |arg| to pass to caller. TAKES OWNERSHIP - a
299 // raw pointer for convenience, since callers usually construct the argument 299 // raw pointer for convenience, since callers usually construct the argument
300 // to this by hand. 300 // to this by hand.
301 ResponseValue OneArgument(base::Value* arg); 301 ResponseValue OneArgument(base::Value* arg);
302 // Success, a single argument |arg| to pass to caller. 302 // Success, a single argument |arg| to pass to caller.
303 ResponseValue OneArgument(scoped_ptr<base::Value> arg); 303 ResponseValue OneArgument(std::unique_ptr<base::Value> arg);
304 // Success, two arguments |arg1| and |arg2| to pass to caller. TAKES 304 // Success, two arguments |arg1| and |arg2| to pass to caller. TAKES
305 // OWNERSHIP - raw pointers for convenience, since callers usually construct 305 // OWNERSHIP - raw pointers for convenience, since callers usually construct
306 // the argument to this by hand. Note that use of this function may imply you 306 // the argument to this by hand. Note that use of this function may imply you
307 // should be using the generated Result struct and ArgumentList. 307 // should be using the generated Result struct and ArgumentList.
308 ResponseValue TwoArguments(base::Value* arg1, base::Value* arg2); 308 ResponseValue TwoArguments(base::Value* arg1, base::Value* arg2);
309 // Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP 309 // Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP
310 // - a scoped_ptr<> for convenience, since callers usually get this from the 310 // - a std::unique_ptr<> for convenience, since callers usually get this from
311 // the
311 // result of a Create(...) call on the generated Results struct, for example, 312 // result of a Create(...) call on the generated Results struct, for example,
312 // alarms::Get::Results::Create(alarm). 313 // alarms::Get::Results::Create(alarm).
313 ResponseValue ArgumentList(scoped_ptr<base::ListValue> results); 314 ResponseValue ArgumentList(std::unique_ptr<base::ListValue> results);
314 // Error. chrome.runtime.lastError.message will be set to |error|. 315 // Error. chrome.runtime.lastError.message will be set to |error|.
315 ResponseValue Error(const std::string& error); 316 ResponseValue Error(const std::string& error);
316 // Error with formatting. Args are processed using 317 // Error with formatting. Args are processed using
317 // ErrorUtils::FormatErrorMessage, that is, each occurence of * is replaced 318 // ErrorUtils::FormatErrorMessage, that is, each occurence of * is replaced
318 // by the corresponding |s*|: 319 // by the corresponding |s*|:
319 // Error("Error in *: *", "foo", "bar") <--> Error("Error in foo: bar"). 320 // Error("Error in *: *", "foo", "bar") <--> Error("Error in foo: bar").
320 ResponseValue Error(const std::string& format, const std::string& s1); 321 ResponseValue Error(const std::string& format, const std::string& s1);
321 ResponseValue Error(const std::string& format, 322 ResponseValue Error(const std::string& format,
322 const std::string& s1, 323 const std::string& s1,
323 const std::string& s2); 324 const std::string& s2);
324 ResponseValue Error(const std::string& format, 325 ResponseValue Error(const std::string& format,
325 const std::string& s1, 326 const std::string& s1,
326 const std::string& s2, 327 const std::string& s2,
327 const std::string& s3); 328 const std::string& s3);
328 // Error with a list of arguments |args| to pass to caller. TAKES OWNERSHIP. 329 // Error with a list of arguments |args| to pass to caller. TAKES OWNERSHIP.
329 // Using this ResponseValue indicates something is wrong with the API. 330 // Using this ResponseValue indicates something is wrong with the API.
330 // It shouldn't be possible to have both an error *and* some arguments. 331 // It shouldn't be possible to have both an error *and* some arguments.
331 // Some legacy APIs do rely on it though, like webstorePrivate. 332 // Some legacy APIs do rely on it though, like webstorePrivate.
332 ResponseValue ErrorWithArguments(scoped_ptr<base::ListValue> args, 333 ResponseValue ErrorWithArguments(std::unique_ptr<base::ListValue> args,
333 const std::string& error); 334 const std::string& error);
334 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(), 335 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(),
335 // so this will actually kill the renderer and not respond at all. 336 // so this will actually kill the renderer and not respond at all.
336 ResponseValue BadMessage(); 337 ResponseValue BadMessage();
337 338
338 // ResponseActions. 339 // ResponseActions.
339 // 340 //
340 // These are exclusively used as return values from Run(). Call Respond(...) 341 // These are exclusively used as return values from Run(). Call Respond(...)
341 // to respond at any other time - but as described below, only after Run() 342 // to respond at any other time - but as described below, only after Run()
342 // has already executed, and only if it returned RespondLater(). 343 // has already executed, and only if it returned RespondLater().
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // True if this callback should include information from incognito contexts 401 // True if this callback should include information from incognito contexts
401 // even if our profile_ is non-incognito. Note that in the case of a "split" 402 // even if our profile_ is non-incognito. Note that in the case of a "split"
402 // mode extension, this will always be false, and we will limit access to 403 // mode extension, this will always be false, and we will limit access to
403 // data from within the same profile_ (either incognito or not). 404 // data from within the same profile_ (either incognito or not).
404 bool include_incognito_; 405 bool include_incognito_;
405 406
406 // True if the call was made in response of user gesture. 407 // True if the call was made in response of user gesture.
407 bool user_gesture_; 408 bool user_gesture_;
408 409
409 // The arguments to the API. Only non-null if argument were specified. 410 // The arguments to the API. Only non-null if argument were specified.
410 scoped_ptr<base::ListValue> args_; 411 std::unique_ptr<base::ListValue> args_;
411 412
412 // The results of the API. This should be populated by the derived class 413 // The results of the API. This should be populated by the derived class
413 // before SendResponse() is called. 414 // before SendResponse() is called.
414 scoped_ptr<base::ListValue> results_; 415 std::unique_ptr<base::ListValue> results_;
415 416
416 // Any detailed error from the API. This should be populated by the derived 417 // Any detailed error from the API. This should be populated by the derived
417 // class before Run() returns. 418 // class before Run() returns.
418 std::string error_; 419 std::string error_;
419 420
420 // Any class that gets a malformed message should set this to true before 421 // Any class that gets a malformed message should set this to true before
421 // returning. Usually we want to kill the message sending process. 422 // returning. Usually we want to kill the message sending process.
422 bool bad_message_; 423 bool bad_message_;
423 424
424 // The sample value to record with the histogram API when the function 425 // The sample value to record with the histogram API when the function
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 class RenderFrameHostTracker; 530 class RenderFrameHostTracker;
530 531
531 void Destruct() const override; 532 void Destruct() const override;
532 533
533 // The dispatcher that will service this extension function call. 534 // The dispatcher that will service this extension function call.
534 base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_; 535 base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_;
535 536
536 // The RenderFrameHost we will send responses to. 537 // The RenderFrameHost we will send responses to.
537 content::RenderFrameHost* render_frame_host_; 538 content::RenderFrameHost* render_frame_host_;
538 539
539 scoped_ptr<RenderFrameHostTracker> tracker_; 540 std::unique_ptr<RenderFrameHostTracker> tracker_;
540 541
541 DelegateForTests* delegate_; 542 DelegateForTests* delegate_;
542 543
543 // The blobs transferred to the renderer process. 544 // The blobs transferred to the renderer process.
544 std::vector<std::string> transferred_blob_uuids_; 545 std::vector<std::string> transferred_blob_uuids_;
545 546
546 DISALLOW_COPY_AND_ASSIGN(UIThreadExtensionFunction); 547 DISALLOW_COPY_AND_ASSIGN(UIThreadExtensionFunction);
547 }; 548 };
548 549
549 // Extension functions that run on the IO thread. This type of function avoids 550 // Extension functions that run on the IO thread. This type of function avoids
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 private: 680 private:
680 // If you're hitting a compile error here due to "final" - great! You're 681 // If you're hitting a compile error here due to "final" - great! You're
681 // doing the right thing, you just need to extend IOThreadExtensionFunction 682 // doing the right thing, you just need to extend IOThreadExtensionFunction
682 // instead of SyncIOExtensionFunction. 683 // instead of SyncIOExtensionFunction.
683 ResponseAction Run() final; 684 ResponseAction Run() final;
684 685
685 DISALLOW_COPY_AND_ASSIGN(SyncIOThreadExtensionFunction); 686 DISALLOW_COPY_AND_ASSIGN(SyncIOThreadExtensionFunction);
686 }; 687 };
687 688
688 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 689 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_error_test_util.cc ('k') | extensions/browser/extension_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698