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

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.h

Issue 85023003: EmbeddedWorker, browser side code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/service_worker/embedded_worker_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h"
15 #include "content/common/content_export.h"
16
17 class GURL;
18
19 namespace content {
20
21 class EmbeddedWorkerRegistry;
22
23 // This gives an interface to control one EmbeddedWorker instance, which
24 // may be 'in-waiting' or running in one of the child processes added by
25 // AddProcessReference().
26 class CONTENT_EXPORT EmbeddedWorkerInstance {
27 public:
28 enum Status {
29 STOPPED,
30 STARTING,
31 RUNNING,
32 STOPPING,
33 };
34
35 ~EmbeddedWorkerInstance();
36
37 // Starts the worker. It is invalid to call this when the worker is
38 // not in STOPPED status.
39 // This returns false if starting a worker fails immediately, e.g. when
40 // IPC couldn't be sent to the worker or no process was available.
41 bool Start(int64 service_worker_version_id,
42 const GURL& script_url);
43
44 // Stops the worker. It is invalid to call this when the worker is
45 // not in STARTING or RUNNING status.
46 // This returns false if stopping a worker fails immediately, e.g. when
47 // IPC couldn't be sent to the worker.
48 bool Stop();
49
50 // Add or remove |process_id| to the internal process set where this
51 // worker can be started.
52 void AddProcessReference(int process_id);
53 void ReleaseProcessReference(int process_id);
54
55 int embedded_worker_id() const { return embedded_worker_id_; }
56 Status status() const { return status_; }
57 int process_id() const { return process_id_; }
58 int thread_id() const { return thread_id_; }
59
60 private:
61 friend class EmbeddedWorkerRegistry;
62 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop);
63
64 typedef std::map<int, int> ProcessRefMap;
65
66 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker().
67 // This instance holds a ref of |registry|.
68 EmbeddedWorkerInstance(EmbeddedWorkerRegistry* registry,
69 int embedded_worker_id);
70
71 // Called back from Registry when the worker instance has ack'ed that
72 // its WorkerGlobalScope is actually started on |thread_id| in the
73 // child process.
74 // This will change the internal status from STARTING to RUNNING.
75 void OnStarted(int thread_id);
76
77 // Called back from Registry when the worker instance has ack'ed that
78 // its WorkerGlobalScope is actually stopped in the child process.
79 // This will change the internal status from STARTING or RUNNING to
80 // STOPPED.
81 void OnStopped();
82
83 // Chooses a process to start this worker and populate process_id_.
84 // Returns false when no process is available.
85 bool ChooseProcess();
86
87 scoped_refptr<EmbeddedWorkerRegistry> registry_;
88 const int embedded_worker_id_;
89 Status status_;
90
91 // Current running information. -1 indicates the worker is not running.
92 int process_id_;
93 int thread_id_;
94
95 ProcessRefMap process_refs_;
96
97 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
98 };
99
100 } // namespace content
101
102 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/embedded_worker_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698