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

Side by Side Diff: goopdate/model.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/model.h ('k') | goopdate/model_object.h » ('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/model.h"
17 #include <algorithm>
18 #include <functional>
19 #include "omaha/base/debug.h"
20 #include "omaha/base/logging.h"
21 #include "omaha/goopdate/worker.h"
22
23 namespace omaha {
24
25 Model::Model(WorkerModelInterface* worker) : worker_(NULL) {
26 CORE_LOG(L3, (_T("[Model::Model]")));
27 ASSERT1(worker);
28
29 // Initialization of the object must be thread safe.
30 __mutexScope(lock_);
31 worker_ = worker;
32 }
33
34 Model::~Model() {
35 CORE_LOG(L3, (_T("[Model::~Model]")));
36
37 __mutexScope(lock_);
38 ASSERT1(app_bundles_.empty());
39 worker_ = NULL;
40 }
41
42 shared_ptr<AppBundle> Model::CreateAppBundle(bool is_machine) {
43 __mutexScope(lock_);
44
45 shared_ptr<AppBundle> app_bundle(new AppBundle(is_machine, this));
46 app_bundles_.push_back(AppBundleWeakPtr(app_bundle));
47
48 const int lock_count(worker_->Lock());
49
50 CORE_LOG(L3, (_T("[Model::CreateAppBundle][bundle %p][module lock %i]"),
51 app_bundle.get(), lock_count));
52
53 return app_bundle;
54 }
55
56 // Erases the expired AppBundle weak pointers.
57 void Model::CleanupExpiredAppBundles() {
58 __mutexScope(lock_);
59
60 typedef std::vector<AppBundleWeakPtr>::iterator Iterator;
61 Iterator it = remove_if(app_bundles_.begin(),
62 app_bundles_.end(),
63 std::mem_fun_ref(&AppBundleWeakPtr::expired));
64
65 const size_t num_bundles = distance(it, app_bundles_.end());
66
67 app_bundles_.erase(it, app_bundles_.end());
68 for (size_t i = 0; i != num_bundles; ++i) {
69 const int lock_count(worker_->Unlock());
70
71 CORE_LOG(L3, (_T("[Model::CleanupExpiredAppBundles][module unlock %i]"),
72 lock_count));
73 }
74 }
75
76 size_t Model::GetNumberOfAppBundles() const {
77 __mutexScope(lock_);
78 return app_bundles_.size();
79 }
80
81 shared_ptr<AppBundle> Model::GetAppBundle(size_t index) const {
82 __mutexScope(lock_);
83 ASSERT1(!app_bundles_[index].expired());
84 return app_bundles_[index].lock();
85 }
86
87 HRESULT Model::CheckForUpdate(AppBundle* app_bundle) {
88 CORE_LOG(L3, (_T("[Model::CheckForUpdate][0x%p]"), app_bundle));
89
90 __mutexScope(lock_);
91
92 return worker_->CheckForUpdateAsync(app_bundle);
93 }
94
95 HRESULT Model::Download(AppBundle* app_bundle) {
96 CORE_LOG(L3, (_T("[Model::Download][0x%p]"), app_bundle));
97
98 __mutexScope(lock_);
99
100 return worker_->DownloadAsync(app_bundle);
101 }
102
103 HRESULT Model::DownloadAndInstall(AppBundle* app_bundle) {
104 CORE_LOG(L3, (_T("[Model::DownloadAndInstall][0x%p]"), app_bundle));
105
106 __mutexScope(lock_);
107
108 return worker_->DownloadAndInstallAsync(app_bundle);
109 }
110
111 HRESULT Model::UpdateAllApps(AppBundle* app_bundle) {
112 CORE_LOG(L3, (_T("[Model::UpdateAllApps][0x%p]"), app_bundle));
113
114 __mutexScope(lock_);
115
116 return worker_->UpdateAllAppsAsync(app_bundle);
117 }
118
119 HRESULT Model::Stop(AppBundle* app_bundle) {
120 CORE_LOG(L3, (_T("[Model::Stop][0x%p]"), app_bundle));
121
122 __mutexScope(lock_);
123
124 return worker_->Stop(app_bundle);
125 }
126
127 HRESULT Model::Pause(AppBundle* app_bundle) {
128 CORE_LOG(L3, (_T("[Model::Pause][0x%p]"), app_bundle));
129
130 __mutexScope(lock_);
131
132 return worker_->Pause(app_bundle);
133 }
134
135 HRESULT Model::Resume(AppBundle* app_bundle) {
136 CORE_LOG(L3, (_T("[Model::Resume][0x%p]"), app_bundle));
137
138 __mutexScope(lock_);
139
140 return worker_->Resume(app_bundle);
141 }
142
143 HRESULT Model::DownloadPackage(Package* package) {
144 CORE_LOG(L3, (_T("[Model::DownloadPackage][0x%p]"), package));
145
146 __mutexScope(lock_);
147
148 return worker_->DownloadPackageAsync(package);
149 }
150
151 HRESULT Model::GetPackage(const Package* package, const CString& dir) const {
152 __mutexScope(lock_);
153
154 return worker_->GetPackage(package, dir);
155 }
156
157 bool Model::IsPackageAvailable(const Package* package) const {
158 __mutexScope(lock_);
159
160 return worker_->IsPackageAvailable(package);
161 }
162
163 HRESULT Model::PurgeAppLowerVersions(const CString& app_id,
164 const CString& version) const {
165 __mutexScope(lock_);
166
167 return worker_->PurgeAppLowerVersions(app_id, version);
168 }
169
170 } // namespace omaha
OLDNEW
« no previous file with comments | « goopdate/model.h ('k') | goopdate/model_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698