 Chromium Code Reviews
 Chromium Code Reviews Issue 85023003:
  EmbeddedWorker, browser side code  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 85023003:
  EmbeddedWorker, browser side code  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: content/browser/service_worker/embedded_worker_instance.h | 
| diff --git a/content/browser/service_worker/embedded_worker_instance.h b/content/browser/service_worker/embedded_worker_instance.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..3c7b3a027fb75dbe1bde9d8505c8670c8ed1e995 | 
| --- /dev/null | 
| +++ b/content/browser/service_worker/embedded_worker_instance.h | 
| @@ -0,0 +1,82 @@ | 
| +// Copyright 2013 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 
| +#define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 
| + | 
| +#include <map> | 
| + | 
| +#include "base/basictypes.h" | 
| +#include "base/callback_forward.h" | 
| +#include "base/logging.h" | 
| +#include "base/memory/ref_counted.h" | 
| + | 
| +class GURL; | 
| + | 
| +namespace content { | 
| + | 
| +class EmbeddedWorkerRegistry; | 
| + | 
| +// This gives an interface to control one EmbeddedWorker instance, which | 
| +// may be 'in-waiting' or running in one of the child processes added by | 
| +// AddProcessReference(). | 
| +class EmbeddedWorkerInstance { | 
| + public: | 
| + enum Status { | 
| + STOPPED, | 
| + STARTING, | 
| + RUNNING, | 
| + STOPPING, | 
| + }; | 
| + | 
| + // This instance holds a ref of |registry|. | 
| + EmbeddedWorkerInstance(EmbeddedWorkerRegistry* registry, | 
| + int embedded_worker_id); | 
| + ~EmbeddedWorkerInstance(); | 
| + | 
| + // Starts the worker. It is invalid to call this when the worker is | 
| + // not in STOPPED status. | 
| + void Start(int64 service_worker_version_id, | 
| + const GURL& script_url); | 
| + | 
| + // Stops the worker. It is invalid to call this when the worker is | 
| + // not in STARTING or RUNNING status. | 
| + void Stop(); | 
| + | 
| + // Called back from Registry. | 
| 
alecflett
2013/12/05 05:18:42
Can you just explain when the registry calls these
 
kinuko
2013/12/09 14:07:42
Done.
I assume eventually SWVersion will implemen
 | 
| + void OnStarted(int thread_id); | 
| + void OnStopped(); | 
| + | 
| + // Add or remove |process_id| to the internal process set where this | 
| + // worker can be started. | 
| + void AddProcessReference(int process_id); | 
| + void ReleaseProcessReference(int process_id); | 
| + | 
| + int embedded_worker_id() const { return embedded_worker_id_; } | 
| + Status status() const { return status_; } | 
| + int process_id() const { return process_id_; } | 
| + int thread_id() const { return thread_id_; } | 
| + | 
| + private: | 
| + typedef std::map<int, int> ProcessRefMap; | 
| + | 
| + // Chooses a process to start this worker. | 
| + int ChooseProcess(); | 
| + | 
| + scoped_refptr<EmbeddedWorkerRegistry> registry_; | 
| + const int embedded_worker_id_; | 
| + Status status_; | 
| + | 
| + // Current running information. -1 indicates the worker is not running. | 
| + int process_id_; | 
| + int thread_id_; | 
| + | 
| + ProcessRefMap process_refs_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 
| +}; | 
| + | 
| +} // namespace content | 
| + | 
| +#endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |