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

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

Issue 950023005: [Extensions] Apply WARN_UNUSED_RESULT and final keyword to ExtensionFunctions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: many comments Created 5 years, 10 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
« no previous file with comments | « chrome/browser/extensions/chrome_extension_function.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // It shouldn't be possible to have both an error *and* some arguments. 314 // It shouldn't be possible to have both an error *and* some arguments.
315 // Some legacy APIs do rely on it though, like webstorePrivate. 315 // Some legacy APIs do rely on it though, like webstorePrivate.
316 ResponseValue ErrorWithArguments(scoped_ptr<base::ListValue> args, 316 ResponseValue ErrorWithArguments(scoped_ptr<base::ListValue> args,
317 const std::string& error); 317 const std::string& error);
318 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(), 318 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(),
319 // so this will actually kill the renderer and not respond at all. 319 // so this will actually kill the renderer and not respond at all.
320 ResponseValue BadMessage(); 320 ResponseValue BadMessage();
321 321
322 // ResponseActions. 322 // ResponseActions.
323 // 323 //
324 // These are exclusively used as return values from Run(). Call Respond(...)
325 // to respond at any other time - but as described below, only after Run()
326 // has already executed, and only if it returned RespondLater().
327 //
Devlin 2015/02/25 16:41:58 More as a note-to-self than anything, but we shoul
not at google - send to devlin 2015/02/25 16:53:57 There is a reason I didn't do this - the most logi
324 // Respond to the extension immediately with |result|. 328 // Respond to the extension immediately with |result|.
325 ResponseAction RespondNow(ResponseValue result); 329 ResponseAction RespondNow(ResponseValue result) WARN_UNUSED_RESULT;
326 // Don't respond now, but promise to call Respond(...) later. 330 // Don't respond now, but promise to call Respond(...) later.
327 ResponseAction RespondLater(); 331 ResponseAction RespondLater() WARN_UNUSED_RESULT;
328 332
329 // This is the return value of the EXTENSION_FUNCTION_VALIDATE macro, which 333 // This is the return value of the EXTENSION_FUNCTION_VALIDATE macro, which
330 // needs to work from Run(), RunAsync(), and RunSync(). The former of those 334 // needs to work from Run(), RunAsync(), and RunSync(). The former of those
331 // has a different return type (ResponseAction) than the latter two (bool). 335 // has a different return type (ResponseAction) than the latter two (bool).
332 static ResponseAction ValidationFailure(ExtensionFunction* function); 336 static ResponseAction ValidationFailure(ExtensionFunction* function)
337 WARN_UNUSED_RESULT;
333 338
334 // If RespondLater() was used, functions must at some point call Respond() 339 // If RespondLater() was returned from Run(), functions must at some point
335 // with |result| as their result. 340 // call Respond() with |result| as their result.
Devlin 2015/02/25 16:41:58 Same - I kind of wonder if we can CHECK on destruc
not at google - send to devlin 2015/02/25 16:53:57 Indeed. Even more complex.
341 //
342 // More specifically: call this iff Run() has already executed, it returned
343 // RespondLater(), and Respond(...) hasn't already been called.
336 void Respond(ResponseValue result); 344 void Respond(ResponseValue result);
337 345
338 virtual ~ExtensionFunction(); 346 virtual ~ExtensionFunction();
339 347
340 // Helper method for ExtensionFunctionDeleteTraits. Deletes this object. 348 // Helper method for ExtensionFunctionDeleteTraits. Deletes this object.
341 virtual void Destruct() const = 0; 349 virtual void Destruct() const = 0;
342 350
343 // Do not call this function directly, return the appropriate ResponseAction 351 // Do not call this function directly, return the appropriate ResponseAction
344 // from Run() instead. If using RespondLater then call Respond(). 352 // from Run() instead. If using RespondLater then call Respond().
345 // 353 //
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 // 589 //
582 // AsyncExtensionFunctions implement this method. Return true to indicate that 590 // AsyncExtensionFunctions implement this method. Return true to indicate that
583 // nothing has gone wrong yet; SendResponse must be called later. Return false 591 // nothing has gone wrong yet; SendResponse must be called later. Return false
584 // to respond immediately with an error. 592 // to respond immediately with an error.
585 virtual bool RunAsync() = 0; 593 virtual bool RunAsync() = 0;
586 594
587 // ValidationFailure override to match RunAsync(). 595 // ValidationFailure override to match RunAsync().
588 static bool ValidationFailure(AsyncExtensionFunction* function); 596 static bool ValidationFailure(AsyncExtensionFunction* function);
589 597
590 private: 598 private:
591 ResponseAction Run() override; 599 // If you're hitting a compile error here due to "final" - great! You're
600 // doing the right thing, you just need to extend UIThreadExtensionFunction
601 // instead of AsyncExtensionFunction.
602 ResponseAction Run() final;
592 }; 603 };
593 604
594 // A SyncExtensionFunction is an ExtensionFunction that runs synchronously 605 // A SyncExtensionFunction is an ExtensionFunction that runs synchronously
595 // *relative to the browser's UI thread*. Note that this has nothing to do with 606 // *relative to the browser's UI thread*. Note that this has nothing to do with
596 // running synchronously relative to the extension process. From the extension 607 // running synchronously relative to the extension process. From the extension
597 // process's point of view, the function is still asynchronous. 608 // process's point of view, the function is still asynchronous.
598 // 609 //
599 // This kind of function is convenient for implementing simple APIs that just 610 // This kind of function is convenient for implementing simple APIs that just
600 // need to interact with things on the browser UI thread. 611 // need to interact with things on the browser UI thread.
601 class SyncExtensionFunction : public UIThreadExtensionFunction { 612 class SyncExtensionFunction : public UIThreadExtensionFunction {
602 public: 613 public:
603 SyncExtensionFunction(); 614 SyncExtensionFunction();
604 615
605 protected: 616 protected:
606 ~SyncExtensionFunction() override; 617 ~SyncExtensionFunction() override;
607 618
608 // Deprecated: Override UIThreadExtensionFunction and implement Run() instead. 619 // Deprecated: Override UIThreadExtensionFunction and implement Run() instead.
609 // 620 //
610 // SyncExtensionFunctions implement this method. Return true to respond 621 // SyncExtensionFunctions implement this method. Return true to respond
611 // immediately with success, false to respond immediately with an error. 622 // immediately with success, false to respond immediately with an error.
612 virtual bool RunSync() = 0; 623 virtual bool RunSync() = 0;
613 624
614 // ValidationFailure override to match RunSync(). 625 // ValidationFailure override to match RunSync().
615 static bool ValidationFailure(SyncExtensionFunction* function); 626 static bool ValidationFailure(SyncExtensionFunction* function);
616 627
617 private: 628 private:
618 ResponseAction Run() override; 629 // If you're hitting a compile error here due to "final" - great! You're
630 // doing the right thing, you just need to extend UIThreadExtensionFunction
631 // instead of SyncExtensionFunction.
632 ResponseAction Run() final;
619 }; 633 };
620 634
621 class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction { 635 class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction {
622 public: 636 public:
623 SyncIOThreadExtensionFunction(); 637 SyncIOThreadExtensionFunction();
624 638
625 protected: 639 protected:
626 ~SyncIOThreadExtensionFunction() override; 640 ~SyncIOThreadExtensionFunction() override;
627 641
628 // Deprecated: Override IOThreadExtensionFunction and implement Run() instead. 642 // Deprecated: Override IOThreadExtensionFunction and implement Run() instead.
629 // 643 //
630 // SyncIOThreadExtensionFunctions implement this method. Return true to 644 // SyncIOThreadExtensionFunctions implement this method. Return true to
631 // respond immediately with success, false to respond immediately with an 645 // respond immediately with success, false to respond immediately with an
632 // error. 646 // error.
633 virtual bool RunSync() = 0; 647 virtual bool RunSync() = 0;
634 648
635 // ValidationFailure override to match RunSync(). 649 // ValidationFailure override to match RunSync().
636 static bool ValidationFailure(SyncIOThreadExtensionFunction* function); 650 static bool ValidationFailure(SyncIOThreadExtensionFunction* function);
637 651
638 private: 652 private:
639 ResponseAction Run() override; 653 // If you're hitting a compile error here due to "final" - great! You're
654 // doing the right thing, you just need to extend IOThreadExtensionFunction
655 // instead of SyncIOExtensionFunction.
656 ResponseAction Run() final;
640 }; 657 };
641 658
642 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 659 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/chrome_extension_function.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698