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

Side by Side Diff: chrome/browser/component_updater/pepper_flash_component_installer.cc

Issue 7604023: Deploy win flapper via component updater (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/component_updater/pepper_flash_component_installer.h"
6
7 #include "base/base_paths.h"
8 #include "base/compiler_specific.h"
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/values.h"
14 #include "chrome/browser/component_updater/component_updater_service.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "content/browser/browser_thread.h"
17
18 namespace {
brettw 2011/08/10 06:04:08 Blank line after this.
cpu_(ooo_6.6-7.5) 2011/08/10 20:08:30 Done.
19 // CRX hash. The extension id is: mimojjlkmoijpicakmndhoigimigcmbb.
20 const uint8 sha2_hash[] = {0xc8, 0xce, 0x99, 0xba, 0xce, 0x89, 0xf8, 0x20,
21 0xac, 0xd3, 0x7e, 0x86, 0x8c, 0x86, 0x2c, 0x11,
22 0xb9, 0x40, 0xc5, 0x55, 0xaf, 0x08, 0x63, 0x70,
23 0x54, 0xf9, 0x56, 0xd3, 0xe7, 0x88, 0xba, 0x8c};
24
25 // File name of the Pepper Flash plugin on different platforms.
26 const FilePath::CharType kPepperFlashPluginFileName[] =
27 #if defined(OS_MACOSX)
28 FILE_PATH_LITERAL("PepperFlashPlayer.plugin");
29 #elif defined(OS_WIN)
30 FILE_PATH_LITERAL("pepflashplayer.dll");
31 #else // OS_LINUX, etc.
32 FILE_PATH_LITERAL("libpepflashplayer.so");
33 #endif
34
35 // File name of the Pepper Flash component manifest on different platforms.
36 const char kPepperFlashManifestName[] =
37 #if defined(OS_MACOSX)
38 "MacFlapper";
39 #elif defined(OS_WIN)
40 "WinFlapper";
41 #else // OS_LINUX, etc.
42 "NixFlapper";
43 #endif
44
45 // The pepper flash plugins are in a directory with this name.
46 const FilePath::CharType kPepperFlashBaseDirectory[] =
47 FILE_PATH_LITERAL("PepperFlash");
48
49 // If we don't have a flash pepper component, this is the version we claim.
50 const char kNullVersion[] = "0.0.0.0";
51
52 FilePath GetPepperFlashBaseDirectory() {
53 FilePath result;
54 PathService::Get(base::DIR_EXE, &result);
brettw 2011/08/10 06:04:08 What happens when you have a system install?
cpu_(ooo_6.6-7.5) 2011/08/10 20:08:30 Sorry, brain fart. Fixed.
55 return result.Append(kPepperFlashBaseDirectory);
56 }
57
58 // Pepper flash plugins have the version encoded in the path itself
59 // so we need to enumerate the directories to find the full path.
60 bool GetLatestPepperFlashDirectory(FilePath* result, Version* latest) {
61 *result = GetPepperFlashBaseDirectory();
62 bool found = false;
63 file_util::FileEnumerator
64 file_enumerator(*result, false, file_util::FileEnumerator::DIRECTORIES);
65 for (FilePath path = file_enumerator.Next(); !path.value().empty();
66 path = file_enumerator.Next()) {
67 Version version(path.BaseName().MaybeAsASCII());
68 if (!version.IsValid())
69 continue;
70 if (version.CompareTo(*latest) > 0) {
71 *latest = version;
72 *result = path;
73 found = true;
74 }
75 }
76 return found;
77 }
78
79 } // namespace
80
81 class PepperFlashComponentInstaller : public ComponentInstaller {
82 public:
83 explicit PepperFlashComponentInstaller(const Version& version);
84
85 virtual ~PepperFlashComponentInstaller() {}
86
87 virtual void OnUpdateError(int error) OVERRIDE;
88
89 virtual bool Install(base::DictionaryValue* manifest,
90 const FilePath& unpack_path) OVERRIDE;
91
92 private:
93 Version current_version_;
94 };
95
96 PepperFlashComponentInstaller::PepperFlashComponentInstaller(
97 const Version& version) : current_version_(version) {
98 DCHECK(version.IsValid());
99 }
100
101 void PepperFlashComponentInstaller::OnUpdateError(int error) {
102 NOTREACHED() << "pepper flash update error :" << error;
103 }
104
105 bool PepperFlashComponentInstaller::Install(base::DictionaryValue* manifest,
106 const FilePath& unpack_path) {
brettw 2011/08/10 06:04:08 Check indent
cpu_(ooo_6.6-7.5) 2011/08/10 20:08:30 Done.
107 std::string name;
108 manifest->GetStringASCII("name", &name);
109 if (name != kPepperFlashManifestName)
110 return false;
111 std::string proposed_version;
112 manifest->GetStringASCII("version", &proposed_version);
113 Version version(proposed_version.c_str());
114 if (!version.IsValid())
115 return false;
116 if (current_version_.CompareTo(version) > 0)
117 return false;
118 if (!file_util::PathExists(unpack_path.Append(kPepperFlashPluginFileName)))
119 return false;
120 // Passed the basic tests. Time to install it.
121 FilePath path =
122 GetPepperFlashBaseDirectory().AppendASCII(version.GetString());
123 if (file_util::PathExists(path))
124 return false;
125 if (!file_util::Move(unpack_path, path))
126 return false;
127 // Installation is done. Now update the path service.
128 current_version_ = version;
129 path = path.Append(kPepperFlashPluginFileName);
130 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path);
131 return true;
132 }
133
134 void FinishPepperFlashRegistration(ComponentUpdateService* cus,
135 const Version& version) {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
137 CrxComponent pepflash;
138 pepflash.name = "pepper_flash";
139 pepflash.installer = new PepperFlashComponentInstaller(version);
140 pepflash.version = version;
141 pepflash.pk_hash.assign(sha2_hash, &sha2_hash[sizeof(sha2_hash)]);
142 if (cus->RegisterComponent(pepflash) != ComponentUpdateService::kOk) {
143 NOTREACHED() << "pepper flash component registration fail";
144 }
145 }
146
147 void StartPepperFlashRegistration(ComponentUpdateService* cus) {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
149 FilePath path = GetPepperFlashBaseDirectory();
150 if (!file_util::PathExists(path)) {
151 if (!file_util::CreateDirectory(path)) {
152 NOTREACHED() << "cannot create pepper flash directory";
153 return;
154 }
155 }
156
157 Version version(kNullVersion);
158 if (GetLatestPepperFlashDirectory(&path, &version)) {
159 path = path.Append(kPepperFlashPluginFileName);
160 if (file_util::PathExists(path))
161 PathService::Override(chrome::FILE_PEPPER_FLASH_PLUGIN, path);
162 else
163 version = Version(kNullVersion);
164 }
165
166 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
167 NewRunnableFunction(&FinishPepperFlashRegistration, cus, version));
168 }
169
170 void RegisterPepperFlashComponent(ComponentUpdateService* cus) {
171 #if !defined(OS_WIN)
172 // TODO(cpu): support Mac and Linux flash pepper.
173 return;
174 #else
175 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
176 NewRunnableFunction(&StartPepperFlashRegistration, cus));
177 #endif
178 }
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/pepper_flash_component_installer.h ('k') | chrome/browser/ui/browser_init.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698