summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_speech_input_manager.h
blob: 4d8ef00c6bd898c2881e8148a01f5bc8b0124103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_
#pragma once

#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
#include <string>

class Extension;
class NotificationDetails;
class NotificationSource;
class Profile;

// Manages the speech input requests and responses from the extensions
// associated to the given profile.
class ExtensionSpeechInputManager : public NotificationObserver,
    public base::RefCountedThreadSafe<ExtensionSpeechInputManager> {
 public:
  // Should not be used directly. Managed by a ProfileKeyedServiceFactory.
  explicit ExtensionSpeechInputManager(Profile* profile);

  // Returns the corresponding manager for the given profile, creating
  // a new one if required.
  static ExtensionSpeechInputManager* GetForProfile(Profile* profile);

  // Initialize the ProfileKeyedServiceFactory.
  static void InitializeFactory();

  // Methods from NotificationObserver.
  virtual void Observe(int type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  // Request to start speech recognition for the provided extension.
  void Start(const Extension *extension);

  // Request to stop an ongoing speech recognition.
  void Stop(const Extension *extension);

  // Called by internal ProfileKeyedService class.
  void ShutdownOnUIThread();

 private:
  void ExtensionUnloaded(const std::string& id);

  friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>;
  class Factory;

  virtual ~ExtensionSpeechInputManager();

  Profile* profile_;
  scoped_refptr<Extension> extension_;
  NotificationRegistrar registrar_;
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_