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

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

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addres comments from falken@ Created 4 years, 2 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 <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.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 "base/timer/elapsed_timer.h" 21 #include "base/timer/elapsed_timer.h"
22 #include "content/common/service_worker/service_worker_types.h"
22 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
23 #include "content/public/common/console_message_level.h" 24 #include "content/public/common/console_message_level.h"
24 #include "extensions/browser/extension_function_histogram_value.h" 25 #include "extensions/browser/extension_function_histogram_value.h"
25 #include "extensions/browser/info_map.h" 26 #include "extensions/browser/info_map.h"
26 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
27 #include "extensions/common/features/feature.h" 28 #include "extensions/common/features/feature.h"
28 #include "ipc/ipc_message.h" 29 #include "ipc/ipc_message.h"
29 30
30 class ExtensionFunction; 31 class ExtensionFunction;
31 class UIThreadExtensionFunction; 32 class UIThreadExtensionFunction;
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 510 }
510 511
511 void set_dispatcher(const base::WeakPtr< 512 void set_dispatcher(const base::WeakPtr<
512 extensions::ExtensionFunctionDispatcher>& dispatcher) { 513 extensions::ExtensionFunctionDispatcher>& dispatcher) {
513 dispatcher_ = dispatcher; 514 dispatcher_ = dispatcher;
514 } 515 }
515 extensions::ExtensionFunctionDispatcher* dispatcher() const { 516 extensions::ExtensionFunctionDispatcher* dispatcher() const {
516 return dispatcher_.get(); 517 return dispatcher_.get();
517 } 518 }
518 519
519 void set_is_from_service_worker(bool value) { 520 void set_service_worker_version_id(int64_t version_id) {
520 is_from_service_worker_ = value; 521 service_worker_version_id_ = version_id;
521 } 522 }
522 523
523 // Gets the "current" web contents if any. If there is no associated web 524 // Gets the "current" web contents if any. If there is no associated web
524 // contents then defaults to the foremost one. 525 // contents then defaults to the foremost one.
525 // NOTE: "current" can mean different things in different contexts. You 526 // NOTE: "current" can mean different things in different contexts. You
526 // probably want to use GetSenderWebContents(). 527 // probably want to use GetSenderWebContents().
527 virtual content::WebContents* GetAssociatedWebContents(); 528 virtual content::WebContents* GetAssociatedWebContents();
528 529
529 // Returns the web contents associated with the sending |render_frame_host_|. 530 // Returns the web contents associated with the sending |render_frame_host_|.
530 // This can be null. 531 // This can be null.
(...skipping 17 matching lines...) Expand all
548 549
549 // The BrowserContext of this function's extension. 550 // The BrowserContext of this function's extension.
550 // TODO(devlin): Grr... protected members. Move this to be private. 551 // TODO(devlin): Grr... protected members. Move this to be private.
551 content::BrowserContext* context_; 552 content::BrowserContext* context_;
552 553
553 private: 554 private:
554 class RenderFrameHostTracker; 555 class RenderFrameHostTracker;
555 556
556 void Destruct() const override; 557 void Destruct() const override;
557 558
559 bool is_from_service_worker() const {
560 return content::kInvalidServiceWorkerVersionId !=
561 service_worker_version_id_;
562 }
563
558 // The dispatcher that will service this extension function call. 564 // The dispatcher that will service this extension function call.
559 base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_; 565 base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_;
560 566
561 // The RenderFrameHost we will send responses to. 567 // The RenderFrameHost we will send responses to.
562 content::RenderFrameHost* render_frame_host_; 568 content::RenderFrameHost* render_frame_host_;
563 569
564 // Whether or not this ExtensionFunction was called by an extension Service 570 // If this ExtensionFunction was called by an extension Service Worker, then
565 // Worker. 571 // this contains the worker's version id.
566 bool is_from_service_worker_; 572 int64_t service_worker_version_id_;
567 573
568 std::unique_ptr<RenderFrameHostTracker> tracker_; 574 std::unique_ptr<RenderFrameHostTracker> tracker_;
569 575
570 // The blobs transferred to the renderer process. 576 // The blobs transferred to the renderer process.
571 std::vector<std::string> transferred_blob_uuids_; 577 std::vector<std::string> transferred_blob_uuids_;
572 578
573 DISALLOW_COPY_AND_ASSIGN(UIThreadExtensionFunction); 579 DISALLOW_COPY_AND_ASSIGN(UIThreadExtensionFunction);
574 }; 580 };
575 581
576 // Extension functions that run on the IO thread. This type of function avoids 582 // Extension functions that run on the IO thread. This type of function avoids
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 private: 656 private:
651 // If you're hitting a compile error here due to "final" - great! You're 657 // If you're hitting a compile error here due to "final" - great! You're
652 // doing the right thing, you just need to extend UIThreadExtensionFunction 658 // doing the right thing, you just need to extend UIThreadExtensionFunction
653 // instead of AsyncExtensionFunction. 659 // instead of AsyncExtensionFunction.
654 ResponseAction Run() final; 660 ResponseAction Run() final;
655 661
656 DISALLOW_COPY_AND_ASSIGN(AsyncExtensionFunction); 662 DISALLOW_COPY_AND_ASSIGN(AsyncExtensionFunction);
657 }; 663 };
658 664
659 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ 665 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698