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

Side by Side Diff: chrome/browser/ui/app_list/start_page_service.cc

Issue 158143002: Fine tuned availability of hotword plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 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 | Annotate | Revision Log
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 #include "chrome/browser/ui/app_list/start_page_service.h" 5 #include "chrome/browser/ui/app_list/start_page_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/extension_system_factory.h"
13 #include "chrome/browser/extensions/install_tracker_factory.h"
14 #include "chrome/browser/media/media_stream_infobar_delegate.h" 12 #include "chrome/browser/media/media_stream_infobar_delegate.h"
15 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/app_list/recommended_apps.h" 14 #include "chrome/browser/ui/app_list/recommended_apps.h"
17 #include "chrome/browser/ui/app_list/start_page_observer.h" 15 #include "chrome/browser/ui/app_list/start_page_observer.h"
16 #include "chrome/browser/ui/app_list/start_page_service_factory.h"
18 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
20 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
21 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
22 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
27 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_delegate.h" 25 #include "content/public/browser/web_contents_delegate.h"
29 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
30 #include "ui/app_list/app_list_switches.h" 27 #include "ui/app_list/app_list_switches.h"
31 28
32 namespace app_list { 29 namespace app_list {
33 30
34 class StartPageService::Factory : public BrowserContextKeyedServiceFactory {
35 public:
36 static StartPageService* GetForProfile(Profile* profile) {
37 if (!CommandLine::ForCurrentProcess()->HasSwitch(
38 ::switches::kShowAppListStartPage) &&
39 !app_list::switches::IsVoiceSearchEnabled()) {
40 return NULL;
41 }
42
43 return static_cast<StartPageService*>(
44 GetInstance()->GetServiceForBrowserContext(profile, true));
45 }
46
47 static Factory* GetInstance() {
48 return Singleton<Factory>::get();
49 }
50
51 private:
52 friend struct DefaultSingletonTraits<Factory>;
53
54 Factory()
55 : BrowserContextKeyedServiceFactory(
56 "AppListStartPageService",
57 BrowserContextDependencyManager::GetInstance()) {
58 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
59 DependsOn(extensions::InstallTrackerFactory::GetInstance());
60 }
61
62 virtual ~Factory() {}
63
64 // BrowserContextKeyedServiceFactory overrides:
65 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
66 content::BrowserContext* context) const OVERRIDE {
67 Profile* profile = static_cast<Profile*>(context);
68 return new StartPageService(profile);
69 }
70
71 DISALLOW_COPY_AND_ASSIGN(Factory);
72 };
73
74 class StartPageService::ProfileDestroyObserver 31 class StartPageService::ProfileDestroyObserver
75 : public content::NotificationObserver { 32 : public content::NotificationObserver {
76 public: 33 public:
77 explicit ProfileDestroyObserver(StartPageService* service) 34 explicit ProfileDestroyObserver(StartPageService* service)
78 : service_(service) { 35 : service_(service) {
79 registrar_.Add(this, 36 registrar_.Add(this,
80 chrome::NOTIFICATION_PROFILE_DESTROYED, 37 chrome::NOTIFICATION_PROFILE_DESTROYED,
81 content::Source<Profile>(service_->profile())); 38 content::Source<Profile>(service_->profile()));
82 } 39 }
83 virtual ~ProfileDestroyObserver() {} 40 virtual ~ProfileDestroyObserver() {}
(...skipping 27 matching lines...) Expand all
111 if (MediaStreamInfoBarDelegate::Create(web_contents, request, callback)) 68 if (MediaStreamInfoBarDelegate::Create(web_contents, request, callback))
112 NOTREACHED() << "Media stream not allowed for WebUI"; 69 NOTREACHED() << "Media stream not allowed for WebUI";
113 } 70 }
114 71
115 private: 72 private:
116 DISALLOW_COPY_AND_ASSIGN(StartPageWebContentsDelegate); 73 DISALLOW_COPY_AND_ASSIGN(StartPageWebContentsDelegate);
117 }; 74 };
118 75
119 // static 76 // static
120 StartPageService* StartPageService::Get(Profile* profile) { 77 StartPageService* StartPageService::Get(Profile* profile) {
121 return Factory::GetForProfile(profile); 78 return StartPageServiceFactory::GetForProfile(profile);
122 } 79 }
123 80
124 StartPageService::StartPageService(Profile* profile) 81 StartPageService::StartPageService(Profile* profile)
125 : profile_(profile), 82 : profile_(profile),
126 profile_destroy_observer_(new ProfileDestroyObserver(this)), 83 profile_destroy_observer_(new ProfileDestroyObserver(this)),
127 recommended_apps_(new RecommendedApps(profile)) { 84 recommended_apps_(new RecommendedApps(profile)),
85 state_(app_list::SPEECH_RECOGNITION_OFF) {
86 #if defined(OS_CHROMEOS)
87 // Updates the default state to hotword listening, because this is
88 // the default behavior. This will be updated when the page is loaded and
89 // the nacl module is loaded.
90 if (app_list::switches::IsVoiceSearchEnabled())
91 state_ = app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING;
92 #endif
93
128 contents_.reset(content::WebContents::Create( 94 contents_.reset(content::WebContents::Create(
129 content::WebContents::CreateParams(profile_))); 95 content::WebContents::CreateParams(profile_)));
130 contents_delegate_.reset(new StartPageWebContentsDelegate()); 96 contents_delegate_.reset(new StartPageWebContentsDelegate());
131 contents_->SetDelegate(contents_delegate_.get()); 97 contents_->SetDelegate(contents_delegate_.get());
132 98
133 GURL url(chrome::kChromeUIAppListStartPageURL); 99 GURL url(chrome::kChromeUIAppListStartPageURL);
134 CommandLine* command_line = CommandLine::ForCurrentProcess(); 100 CommandLine* command_line = CommandLine::ForCurrentProcess();
135 if (command_line->HasSwitch(::switches::kAppListStartPageURL)) { 101 if (command_line->HasSwitch(::switches::kAppListStartPageURL)) {
136 url = GURL( 102 url = GURL(
137 command_line->GetSwitchValueASCII(::switches::kAppListStartPageURL)); 103 command_line->GetSwitchValueASCII(::switches::kAppListStartPageURL));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 142 }
177 143
178 void StartPageService::OnSpeechSoundLevelChanged(int16 level) { 144 void StartPageService::OnSpeechSoundLevelChanged(int16 level) {
179 FOR_EACH_OBSERVER(StartPageObserver, 145 FOR_EACH_OBSERVER(StartPageObserver,
180 observers_, 146 observers_,
181 OnSpeechSoundLevelChanged(level)); 147 OnSpeechSoundLevelChanged(level));
182 } 148 }
183 149
184 void StartPageService::OnSpeechRecognitionStateChanged( 150 void StartPageService::OnSpeechRecognitionStateChanged(
185 SpeechRecognitionState new_state) { 151 SpeechRecognitionState new_state) {
152 state_ = new_state;
186 FOR_EACH_OBSERVER(StartPageObserver, 153 FOR_EACH_OBSERVER(StartPageObserver,
187 observers_, 154 observers_,
188 OnSpeechRecognitionStateChanged(new_state)); 155 OnSpeechRecognitionStateChanged(new_state));
189 } 156 }
190 157
191 void StartPageService::Shutdown() { 158 void StartPageService::Shutdown() {
192 contents_.reset(); 159 contents_.reset();
193 } 160 }
194 161
195 } // namespace app_list 162 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/start_page_service.h ('k') | chrome/browser/ui/app_list/start_page_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698