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

Side by Side Diff: extensions/browser/api/app_runtime/app_runtime_api.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/app_runtime/app_runtime_api.h" 5 #include "extensions/browser/api/app_runtime/app_runtime_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 using content::BrowserContext; 24 using content::BrowserContext;
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 namespace app_runtime = api::app_runtime; 28 namespace app_runtime = api::app_runtime;
29 29
30 namespace { 30 namespace {
31 31
32 void DispatchOnEmbedRequestedEventImpl( 32 void DispatchOnEmbedRequestedEventImpl(
33 const std::string& extension_id, 33 const std::string& extension_id,
34 scoped_ptr<base::DictionaryValue> app_embedding_request_data, 34 std::unique_ptr<base::DictionaryValue> app_embedding_request_data,
35 content::BrowserContext* context) { 35 content::BrowserContext* context) {
36 scoped_ptr<base::ListValue> args(new base::ListValue()); 36 std::unique_ptr<base::ListValue> args(new base::ListValue());
37 args->Append(app_embedding_request_data.release()); 37 args->Append(app_embedding_request_data.release());
38 scoped_ptr<Event> event(new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED, 38 std::unique_ptr<Event> event(
39 app_runtime::OnEmbedRequested::kEventName, 39 new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED,
40 std::move(args))); 40 app_runtime::OnEmbedRequested::kEventName, std::move(args)));
41 event->restrict_to_browser_context = context; 41 event->restrict_to_browser_context = context;
42 EventRouter::Get(context) 42 EventRouter::Get(context)
43 ->DispatchEventWithLazyListener(extension_id, std::move(event)); 43 ->DispatchEventWithLazyListener(extension_id, std::move(event));
44 44
45 ExtensionPrefs::Get(context) 45 ExtensionPrefs::Get(context)
46 ->SetLastLaunchTime(extension_id, base::Time::Now()); 46 ->SetLastLaunchTime(extension_id, base::Time::Now());
47 } 47 }
48 48
49 void DispatchOnLaunchedEventImpl(const std::string& extension_id, 49 void DispatchOnLaunchedEventImpl(
50 app_runtime::LaunchSource source, 50 const std::string& extension_id,
51 scoped_ptr<base::DictionaryValue> launch_data, 51 app_runtime::LaunchSource source,
52 BrowserContext* context) { 52 std::unique_ptr<base::DictionaryValue> launch_data,
53 BrowserContext* context) {
53 UMA_HISTOGRAM_ENUMERATION( 54 UMA_HISTOGRAM_ENUMERATION(
54 "Extensions.AppLaunchSource", source, NUM_APP_LAUNCH_SOURCES); 55 "Extensions.AppLaunchSource", source, NUM_APP_LAUNCH_SOURCES);
55 56
56 // "Forced app mode" is true for Chrome OS kiosk mode. 57 // "Forced app mode" is true for Chrome OS kiosk mode.
57 launch_data->SetBoolean( 58 launch_data->SetBoolean(
58 "isKioskSession", 59 "isKioskSession",
59 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()); 60 ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode());
60 61
61 launch_data->SetBoolean( 62 launch_data->SetBoolean(
62 "isPublicSession", 63 "isPublicSession",
63 ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount()); 64 ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount());
64 65
65 scoped_ptr<base::ListValue> args(new base::ListValue()); 66 std::unique_ptr<base::ListValue> args(new base::ListValue());
66 args->Append(launch_data.release()); 67 args->Append(launch_data.release());
67 scoped_ptr<Event> event(new Event(events::APP_RUNTIME_ON_LAUNCHED, 68 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_LAUNCHED,
68 app_runtime::OnLaunched::kEventName, 69 app_runtime::OnLaunched::kEventName,
69 std::move(args))); 70 std::move(args)));
70 event->restrict_to_browser_context = context; 71 event->restrict_to_browser_context = context;
71 EventRouter::Get(context) 72 EventRouter::Get(context)
72 ->DispatchEventWithLazyListener(extension_id, std::move(event)); 73 ->DispatchEventWithLazyListener(extension_id, std::move(event));
73 ExtensionPrefs::Get(context) 74 ExtensionPrefs::Get(context)
74 ->SetLastLaunchTime(extension_id, base::Time::Now()); 75 ->SetLastLaunchTime(extension_id, base::Time::Now());
75 } 76 }
76 77
77 app_runtime::LaunchSource getLaunchSourceEnum( 78 app_runtime::LaunchSource getLaunchSourceEnum(
78 extensions::AppLaunchSource source) { 79 extensions::AppLaunchSource source) {
79 switch (source) { 80 switch (source) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 default: 118 default:
118 return app_runtime::LAUNCH_SOURCE_NONE; 119 return app_runtime::LAUNCH_SOURCE_NONE;
119 } 120 }
120 } 121 }
121 122
122 } // namespace 123 } // namespace
123 124
124 // static 125 // static
125 void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( 126 void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent(
126 content::BrowserContext* context, 127 content::BrowserContext* context,
127 scoped_ptr<base::DictionaryValue> embed_app_data, 128 std::unique_ptr<base::DictionaryValue> embed_app_data,
128 const Extension* extension) { 129 const Extension* extension) {
129 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data), 130 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data),
130 context); 131 context);
131 } 132 }
132 133
133 // static 134 // static
134 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( 135 void AppRuntimeEventRouter::DispatchOnLaunchedEvent(
135 BrowserContext* context, 136 BrowserContext* context,
136 const Extension* extension, 137 const Extension* extension,
137 extensions::AppLaunchSource source) { 138 extensions::AppLaunchSource source) {
138 app_runtime::LaunchData launch_data; 139 app_runtime::LaunchData launch_data;
139 140
140 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); 141 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source);
141 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { 142 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
142 launch_data.source = source_enum; 143 launch_data.source = source_enum;
143 } 144 }
144 DispatchOnLaunchedEventImpl(extension->id(), source_enum, 145 DispatchOnLaunchedEventImpl(extension->id(), source_enum,
145 launch_data.ToValue(), context); 146 launch_data.ToValue(), context);
146 } 147 }
147 148
148 // static 149 // static
149 void AppRuntimeEventRouter::DispatchOnRestartedEvent( 150 void AppRuntimeEventRouter::DispatchOnRestartedEvent(
150 BrowserContext* context, 151 BrowserContext* context,
151 const Extension* extension) { 152 const Extension* extension) {
152 scoped_ptr<base::ListValue> arguments(new base::ListValue()); 153 std::unique_ptr<base::ListValue> arguments(new base::ListValue());
153 scoped_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, 154 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED,
154 app_runtime::OnRestarted::kEventName, 155 app_runtime::OnRestarted::kEventName,
155 std::move(arguments))); 156 std::move(arguments)));
156 event->restrict_to_browser_context = context; 157 event->restrict_to_browser_context = context;
157 EventRouter::Get(context) 158 EventRouter::Get(context)
158 ->DispatchEventToExtension(extension->id(), std::move(event)); 159 ->DispatchEventToExtension(extension->id(), std::move(event));
159 } 160 }
160 161
161 // static 162 // static
162 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( 163 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries(
163 BrowserContext* context, 164 BrowserContext* context,
164 const Extension* extension, 165 const Extension* extension,
165 const std::string& handler_id, 166 const std::string& handler_id,
166 const std::vector<EntryInfo>& entries, 167 const std::vector<EntryInfo>& entries,
167 const std::vector<GrantedFileEntry>& file_entries) { 168 const std::vector<GrantedFileEntry>& file_entries) {
168 // TODO(sergeygs): Use the same way of creating an event (using the generated 169 // TODO(sergeygs): Use the same way of creating an event (using the generated
169 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. 170 // boilerplate) as below in DispatchOnLaunchedEventWithUrl.
170 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); 171 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue);
171 launch_data->SetString("id", handler_id); 172 launch_data->SetString("id", handler_id);
172 173
173 app_runtime::LaunchSource source_enum = 174 app_runtime::LaunchSource source_enum =
174 app_runtime::LAUNCH_SOURCE_FILE_HANDLER; 175 app_runtime::LAUNCH_SOURCE_FILE_HANDLER;
175 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { 176 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
176 launch_data->SetString("source", app_runtime::ToString(source_enum)); 177 launch_data->SetString("source", app_runtime::ToString(source_enum));
177 } 178 }
178 179
179 scoped_ptr<base::ListValue> items(new base::ListValue); 180 std::unique_ptr<base::ListValue> items(new base::ListValue);
180 DCHECK(file_entries.size() == entries.size()); 181 DCHECK(file_entries.size() == entries.size());
181 for (size_t i = 0; i < file_entries.size(); ++i) { 182 for (size_t i = 0; i < file_entries.size(); ++i) {
182 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue); 183 std::unique_ptr<base::DictionaryValue> launch_item(
184 new base::DictionaryValue);
183 185
184 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); 186 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id);
185 launch_item->SetString("baseName", file_entries[i].registered_name); 187 launch_item->SetString("baseName", file_entries[i].registered_name);
186 launch_item->SetString("mimeType", entries[i].mime_type); 188 launch_item->SetString("mimeType", entries[i].mime_type);
187 launch_item->SetString("entryId", file_entries[i].id); 189 launch_item->SetString("entryId", file_entries[i].id);
188 launch_item->SetBoolean("isDirectory", entries[i].is_directory); 190 launch_item->SetBoolean("isDirectory", entries[i].is_directory);
189 items->Append(launch_item.release()); 191 items->Append(launch_item.release());
190 } 192 }
191 launch_data->Set("items", items.release()); 193 launch_data->Set("items", items.release());
192 DispatchOnLaunchedEventImpl(extension->id(), source_enum, 194 DispatchOnLaunchedEventImpl(extension->id(), source_enum,
(...skipping 14 matching lines...) Expand all
207 launch_data.url.reset(new std::string(url.spec())); 209 launch_data.url.reset(new std::string(url.spec()));
208 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); 210 launch_data.referrer_url.reset(new std::string(referrer_url.spec()));
209 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { 211 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
210 launch_data.source = source_enum; 212 launch_data.source = source_enum;
211 } 213 }
212 DispatchOnLaunchedEventImpl(extension->id(), source_enum, 214 DispatchOnLaunchedEventImpl(extension->id(), source_enum,
213 launch_data.ToValue(), context); 215 launch_data.ToValue(), context);
214 } 216 }
215 217
216 } // namespace extensions 218 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/app_runtime/app_runtime_api.h ('k') | extensions/browser/api/app_window/app_window_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698