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

Side by Side Diff: chrome/browser/extensions/launch_util.cc

Issue 93883004: Sync the launch type pref for apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test for invalid value, make tests actually check things Created 6 years, 11 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/extensions/launch_util.h" 5 #include "chrome/browser/extensions/launch_util.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_prefs.h" 9 #include "chrome/browser/extensions/extension_prefs.h"
10 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/ui/host_desktop.h" 11 #include "chrome/browser/ui/host_desktop.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension_constants.h" 13 #include "chrome/common/extensions/extension_constants.h"
13 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 14 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
14 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
15 16
16 #if defined(OS_WIN) 17 #if defined(OS_WIN)
17 #include "win8/util/win8_util.h" 18 #include "win8/util/win8_util.h"
18 #endif 19 #endif
19 20
20 #if defined(USE_ASH) 21 #if defined(USE_ASH)
21 #include "ash/shell.h" 22 #include "ash/shell.h"
22 #endif 23 #endif
23 24
24 namespace extensions { 25 namespace extensions {
25 namespace { 26 namespace {
26 27
27 // A preference set by the the NTP to persist the desired launch container type 28 // A preference set by the the NTP to persist the desired launch container type
28 // used for apps. 29 // used for apps.
29 const char kPrefLaunchType[] = "launchType"; 30 const char kPrefLaunchType[] = "launchType";
30 31
31 } // namespace 32 } // namespace
32 33
33 LaunchType GetLaunchType(const ExtensionPrefs* prefs, 34 LaunchType GetLaunchType(const ExtensionPrefs* prefs,
34 const Extension* extension) { 35 const Extension* extension) {
35 int value = -1;
36 LaunchType result = LAUNCH_TYPE_DEFAULT; 36 LaunchType result = LAUNCH_TYPE_DEFAULT;
37 37
38 // Launch hosted apps as windows by default for streamlined hosted apps. 38 // Launch hosted apps as windows by default for streamlined hosted apps.
39 if (CommandLine::ForCurrentProcess()-> 39 if (CommandLine::ForCurrentProcess()->
40 HasSwitch(switches::kEnableStreamlinedHostedApps) && 40 HasSwitch(switches::kEnableStreamlinedHostedApps) &&
41 extension->id() != extension_misc::kChromeAppId) { 41 extension->id() != extension_misc::kChromeAppId) {
42 result = LAUNCH_TYPE_WINDOW; 42 result = LAUNCH_TYPE_WINDOW;
43 } 43 }
44 44
45 if (prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value) && 45 int value = GetLaunchTypePrefValue(prefs, extension->id());
46 (value == LAUNCH_TYPE_PINNED || 46 if (value >= LAUNCH_TYPE_FIRST && value < NUM_LAUNCH_TYPES)
47 value == LAUNCH_TYPE_REGULAR ||
48 value == LAUNCH_TYPE_FULLSCREEN ||
49 value == LAUNCH_TYPE_WINDOW)) {
50 result = static_cast<LaunchType>(value); 47 result = static_cast<LaunchType>(value);
51 } 48
52 #if defined(OS_MACOSX) 49 #if defined(OS_MACOSX)
53 // App windows are not yet supported on mac. Pref sync could make 50 // App windows are not yet supported on mac. Pref sync could make
54 // the launch type LAUNCH_TYPE_WINDOW, even if there is no UI to set it 51 // the launch type LAUNCH_TYPE_WINDOW, even if there is no UI to set it
55 // on mac. 52 // on mac.
56 if (!extension->is_platform_app() && result == LAUNCH_TYPE_WINDOW) 53 if (!extension->is_platform_app() && result == LAUNCH_TYPE_WINDOW)
57 result = LAUNCH_TYPE_REGULAR; 54 result = LAUNCH_TYPE_REGULAR;
58 #endif 55 #endif
59 56
60 #if defined(OS_WIN) 57 #if defined(OS_WIN)
61 // We don't support app windows in Windows 8 single window Metro mode. 58 // We don't support app windows in Windows 8 single window Metro mode.
62 if (win8::IsSingleWindowMetroMode() && result == LAUNCH_TYPE_WINDOW) 59 if (win8::IsSingleWindowMetroMode() && result == LAUNCH_TYPE_WINDOW)
63 result = LAUNCH_TYPE_REGULAR; 60 result = LAUNCH_TYPE_REGULAR;
64 #endif // OS_WIN 61 #endif // OS_WIN
65 62
66 return result; 63 return result;
67 } 64 }
68 65
69 void SetLaunchType(ExtensionPrefs* prefs, 66 LaunchType GetLaunchTypePrefValue(const ExtensionPrefs* prefs,
67 const std::string& extension_id) {
68 int value = LAUNCH_TYPE_INVALID;
69 return prefs->ReadPrefAsInteger(extension_id, kPrefLaunchType, &value)
70 ? static_cast<LaunchType>(value) : LAUNCH_TYPE_INVALID;
71 }
72
73 void SetLaunchType(ExtensionService* service,
70 const std::string& extension_id, 74 const std::string& extension_id,
71 LaunchType launch_type) { 75 LaunchType launch_type) {
72 prefs->UpdateExtensionPref(extension_id, kPrefLaunchType, 76 DCHECK(launch_type >= LAUNCH_TYPE_FIRST && launch_type < NUM_LAUNCH_TYPES);
77
78 service->extension_prefs()->UpdateExtensionPref(extension_id, kPrefLaunchType,
73 new base::FundamentalValue(static_cast<int>(launch_type))); 79 new base::FundamentalValue(static_cast<int>(launch_type)));
80
81 // Sync the launch type.
82 const Extension* extension = service->GetInstalledExtension(extension_id);
83 if (extension) {
84 ExtensionSyncService::Get(service->profile())->
85 SyncExtensionChangeIfNeeded(*extension);
86 }
74 } 87 }
75 88
76 LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs, 89 LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs,
77 const Extension* extension) { 90 const Extension* extension) {
78 LaunchContainer manifest_launch_container = 91 LaunchContainer manifest_launch_container =
79 AppLaunchInfo::GetLaunchContainer(extension); 92 AppLaunchInfo::GetLaunchContainer(extension);
80 93
81 const LaunchContainer kInvalidLaunchContainer = 94 const LaunchContainer kInvalidLaunchContainer =
82 static_cast<LaunchContainer>(-1); 95 static_cast<LaunchContainer>(-1);
83 96
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs, 142 bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs,
130 const Extension* extension) { 143 const Extension* extension) {
131 int value = -1; 144 int value = -1;
132 LaunchContainer manifest_launch_container = 145 LaunchContainer manifest_launch_container =
133 AppLaunchInfo::GetLaunchContainer(extension); 146 AppLaunchInfo::GetLaunchContainer(extension);
134 return manifest_launch_container == LAUNCH_CONTAINER_TAB && 147 return manifest_launch_container == LAUNCH_CONTAINER_TAB &&
135 prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value); 148 prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value);
136 } 149 }
137 150
138 } // namespace extensions 151 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698