OLD | NEW |
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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // BrowserContextKeyedServiceFactory overrides: | 57 // BrowserContextKeyedServiceFactory overrides: |
58 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 58 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
59 content::BrowserContext* context) const OVERRIDE { | 59 content::BrowserContext* context) const OVERRIDE { |
60 Profile* profile = static_cast<Profile*>(context); | 60 Profile* profile = static_cast<Profile*>(context); |
61 return new StartPageService(profile); | 61 return new StartPageService(profile); |
62 } | 62 } |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(Factory); | 64 DISALLOW_COPY_AND_ASSIGN(Factory); |
65 }; | 65 }; |
66 | 66 |
67 class StartPageService::ExitObserver : public content::NotificationObserver { | 67 class StartPageService::ProfileDestroyObserver |
| 68 : public content::NotificationObserver { |
68 public: | 69 public: |
69 explicit ExitObserver(StartPageService* service) : service_(service) { | 70 explicit ProfileDestroyObserver(StartPageService* service) |
| 71 : service_(service) { |
70 registrar_.Add(this, | 72 registrar_.Add(this, |
71 chrome::NOTIFICATION_APP_TERMINATING, | 73 chrome::NOTIFICATION_PROFILE_DESTROYED, |
72 content::NotificationService::AllSources()); | 74 content::NotificationService::AllSources()); |
73 } | 75 } |
74 virtual ~ExitObserver() {} | 76 virtual ~ProfileDestroyObserver() {} |
75 | 77 |
76 private: | 78 private: |
77 // content::NotificationObserver | 79 // content::NotificationObserver |
78 virtual void Observe(int type, | 80 virtual void Observe(int type, |
79 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
80 const content::NotificationDetails& details) OVERRIDE { | 82 const content::NotificationDetails& details) OVERRIDE { |
81 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); | 83 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
82 service_->Shutdown(); | 84 service_->Shutdown(); |
83 } | 85 } |
84 | 86 |
85 StartPageService* service_; // Owner of this class. | 87 StartPageService* service_; // Owner of this class. |
86 content::NotificationRegistrar registrar_; | 88 content::NotificationRegistrar registrar_; |
87 | 89 |
88 DISALLOW_COPY_AND_ASSIGN(ExitObserver); | 90 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyObserver); |
89 }; | 91 }; |
90 | 92 |
91 // static | 93 // static |
92 StartPageService* StartPageService::Get(Profile* profile) { | 94 StartPageService* StartPageService::Get(Profile* profile) { |
93 return Factory::GetForProfile(profile); | 95 return Factory::GetForProfile(profile); |
94 } | 96 } |
95 | 97 |
96 StartPageService::StartPageService(Profile* profile) | 98 StartPageService::StartPageService(Profile* profile) |
97 : profile_(profile), | 99 : profile_(profile), |
98 exit_observer_(new ExitObserver(this)), | 100 profile_destroy_observer_(new ProfileDestroyObserver(this)), |
99 recommended_apps_(new RecommendedApps(profile)) { | 101 recommended_apps_(new RecommendedApps(profile)) { |
100 contents_.reset(content::WebContents::Create( | 102 contents_.reset(content::WebContents::Create( |
101 content::WebContents::CreateParams(profile_))); | 103 content::WebContents::CreateParams(profile_))); |
102 | 104 |
103 GURL url(chrome::kChromeUIAppListStartPageURL); | 105 GURL url(chrome::kChromeUIAppListStartPageURL); |
104 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 106 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
105 if (command_line->HasSwitch(switches::kAppListStartPageURL)) { | 107 if (command_line->HasSwitch(switches::kAppListStartPageURL)) { |
106 url = GURL( | 108 url = GURL( |
107 command_line->GetSwitchValueASCII(switches::kAppListStartPageURL)); | 109 command_line->GetSwitchValueASCII(switches::kAppListStartPageURL)); |
108 } | 110 } |
109 | 111 |
110 contents_->GetController().LoadURL( | 112 contents_->GetController().LoadURL( |
111 url, | 113 url, |
112 content::Referrer(), | 114 content::Referrer(), |
113 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 115 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
114 std::string()); | 116 std::string()); |
115 } | 117 } |
116 | 118 |
117 StartPageService::~StartPageService() {} | 119 StartPageService::~StartPageService() {} |
118 | 120 |
119 void StartPageService::Shutdown() { | 121 void StartPageService::Shutdown() { |
120 contents_.reset(); | 122 contents_.reset(); |
121 } | 123 } |
122 | 124 |
123 } // namespace app_list | 125 } // namespace app_list |
OLD | NEW |