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

Side by Side Diff: goopdate/app_version.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « goopdate/app_version.h ('k') | goopdate/app_version_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009-2010 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/goopdate/app_version.h"
17 #include <atlsafe.h>
18 #include "omaha/base/debug.h"
19 #include "omaha/base/logging.h"
20 #include "omaha/base/scoped_ptr_address.h"
21 #include "omaha/base/synchronized.h"
22 #include "omaha/base/utils.h"
23 #include "omaha/goopdate/model.h"
24
25 namespace omaha {
26
27 AppVersion::AppVersion(App* app)
28 : ModelObject(app->model()),
29 app_(app) {
30 }
31
32 // Destruction of App objects happens within the scope of their parent,
33 // which controls the locking.
34 AppVersion::~AppVersion() {
35 ASSERT1(model()->IsLockedByCaller());
36
37 for (size_t i = 0; i < packages_.size(); ++i) {
38 delete packages_[i];
39 }
40 }
41
42 CString AppVersion::version() const {
43 __mutexScope(model()->lock());
44 return version_;
45 }
46
47 void AppVersion::set_version(const CString& version) {
48 __mutexScope(model()->lock());
49 version_ = version;
50 }
51
52 App* AppVersion::app() {
53 __mutexScope(model()->lock());
54 return app_;
55 }
56
57 const App* AppVersion::app() const {
58 __mutexScope(model()->lock());
59 return app_;
60 }
61
62 // TODO(omaha3): It's unfortunate that the manifest can be empty. We need to
63 // make a copy anyway in UpdateResponse::BuildApp, so maybe this class
64 // should just expose a manifest object created in the constructor. On the
65 // other hand, current_version may not have a manifest, so this would be an
66 // empty object. Because the manifest must be created, AppData must friend
67 // InstallManager tests and other tests that need a manifest. This could
68 // probably be solved through mocking too.
69 const xml::InstallManifest* AppVersion::install_manifest() const {
70 __mutexScope(model()->lock());
71 return install_manifest_.get();
72 }
73
74 void AppVersion::set_install_manifest(xml::InstallManifest* install_manifest) {
75 __mutexScope(model()->lock());
76 ASSERT1(install_manifest);
77 install_manifest_.reset(install_manifest);
78 }
79
80 size_t AppVersion::GetNumberOfPackages() const {
81 __mutexScope(model()->lock());
82 return packages_.size();
83 }
84
85 HRESULT AppVersion::AddPackage(const CString& filename,
86 uint32 size,
87 const CString& hash) {
88 __mutexScope(model()->lock());
89 Package* package = new Package(this);
90 package->SetFileInfo(filename, size, hash);
91 packages_.push_back(package);
92 return S_OK;
93 }
94
95 Package* AppVersion::GetPackage(size_t index) {
96 __mutexScope(model()->lock());
97
98 if (index >= GetNumberOfPackages()) {
99 ASSERT1(false);
100 return NULL;
101 }
102
103 return packages_[index];
104 }
105
106 const Package* AppVersion::GetPackage(size_t index) const {
107 __mutexScope(model()->lock());
108
109 if (index >= GetNumberOfPackages()) {
110 ASSERT1(false);
111 return NULL;
112 }
113
114 return packages_[index];
115 }
116
117 const std::vector<CString>& AppVersion::download_base_urls() const {
118 __mutexScope(model()->lock());
119 ASSERT1(!download_base_urls_.empty());
120 return download_base_urls_;
121 }
122
123 HRESULT AppVersion::AddDownloadBaseUrl(const CString& base_url) {
124 __mutexScope(model()->lock());
125 ASSERT1(!base_url.IsEmpty());
126 download_base_urls_.push_back(base_url);
127 return S_OK;
128 }
129
130 // IAppVersion.
131 STDMETHODIMP AppVersion::get_version(BSTR* version) {
132 __mutexScope(model()->lock());
133 ASSERT1(version);
134 *version = version_.AllocSysString();
135 return S_OK;
136 }
137
138 STDMETHODIMP AppVersion::get_packageCount(long* count) { // NOLINT
139 __mutexScope(model()->lock());
140
141 *count = GetNumberOfPackages();
142 return S_OK;
143 }
144
145 STDMETHODIMP AppVersion::get_package(long index, Package** package) { // NOLINT
146 __mutexScope(model()->lock());
147
148 if (index < 0 || static_cast<size_t>(index) >= GetNumberOfPackages()) {
149 return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
150 }
151
152 *package = GetPackage(index);
153 return S_OK;
154 }
155
156 STDMETHODIMP AppVersionWrapper::get_version(BSTR* version) {
157 __mutexScope(model()->lock());
158 return wrapped_obj()->get_version(version);
159 }
160
161 STDMETHODIMP AppVersionWrapper::get_packageCount(long* count) { // NOLINT
162 __mutexScope(model()->lock());
163 return wrapped_obj()->get_packageCount(count);
164 }
165
166 STDMETHODIMP AppVersionWrapper::get_package(long index, // NOLINT
167 IDispatch** package) {
168 __mutexScope(model()->lock());
169
170 Package* p = NULL;
171 HRESULT hr = wrapped_obj()->get_package(index, &p);
172 if (FAILED(hr)) {
173 return hr;
174 }
175
176 return PackageWrapper::Create(controlling_ptr(), p, package);
177 }
178
179 HRESULT CopyAppVersionPackages(const AppVersion* app_version,
180 const CString& dir) {
181 ASSERT1(app_version);
182
183 HRESULT hr(CreateDir(dir, NULL));
184 if (FAILED(hr)) {
185 return hr;
186 }
187
188 for (size_t i = 0; i != app_version->GetNumberOfPackages(); ++i) {
189 const Package* package = app_version->GetPackage(i);
190 ASSERT1(package);
191 if (package) {
192 hr = package->get(CComBSTR(dir));
193 if (FAILED(hr)) {
194 CORE_LOG(LE, (_T("[Package::get failed][%s][%s][0x%x]"),
195 package->filename(), dir, hr));
196 return hr;
197 }
198 }
199 }
200
201 return S_OK;
202 }
203
204 } // namespace omaha
OLDNEW
« no previous file with comments | « goopdate/app_version.h ('k') | goopdate/app_version_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698