| OLD | NEW |
| (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 #ifndef OMAHA_GOOPDATE_APP_STATE_H_ | |
| 17 #define OMAHA_GOOPDATE_APP_STATE_H_ | |
| 18 | |
| 19 #include <windows.h> | |
| 20 #include <atlstr.h> | |
| 21 #include "base/basictypes.h" | |
| 22 #include "base/scoped_ptr.h" | |
| 23 #include "omaha/common/const_goopdate.h" | |
| 24 #include "omaha/common/ping_event.h" | |
| 25 #include "omaha/goopdate/installer_result_info.h" | |
| 26 #include "goopdate/omaha3_idl.h" | |
| 27 | |
| 28 namespace omaha { | |
| 29 | |
| 30 class App; | |
| 31 struct ErrorContext; | |
| 32 class DownloadManagerInterface; | |
| 33 class InstallManagerInterface; | |
| 34 | |
| 35 namespace xml { | |
| 36 | |
| 37 class UpdateRequest; | |
| 38 class UpdateResponse; | |
| 39 | |
| 40 } // namespace xml | |
| 41 | |
| 42 namespace fsm { | |
| 43 | |
| 44 // Defines the interface for encapsulating behavior associated with a particular | |
| 45 // state of the App object. | |
| 46 // All state transition calls should go through App, meaning it is the only | |
| 47 // class that should use this interface. | |
| 48 class AppState { | |
| 49 public: | |
| 50 virtual ~AppState() {} | |
| 51 | |
| 52 // Design note: avoid switch and conditional statements on CurrentState. They | |
| 53 // break polymorphism and they are a poor substitute for RTTI. | |
| 54 CurrentState state() const { return state_; } | |
| 55 | |
| 56 // Creates a ping event for the current state. The caller owns the returned | |
| 57 // object. | |
| 58 virtual const PingEvent* CreatePingEvent(App* app, | |
| 59 CurrentState previous_state) const; | |
| 60 | |
| 61 virtual void QueueUpdateCheck(App* app); | |
| 62 | |
| 63 virtual void PreUpdateCheck(App* app, xml::UpdateRequest* update_request); | |
| 64 | |
| 65 virtual void PostUpdateCheck(App* app, | |
| 66 HRESULT result, | |
| 67 xml::UpdateResponse* update_response); | |
| 68 | |
| 69 virtual void QueueDownload(App* app); | |
| 70 | |
| 71 // Queues the download for a download and install operation. | |
| 72 virtual void QueueDownloadOrInstall(App* app); | |
| 73 | |
| 74 virtual void Download(App* app, DownloadManagerInterface* download_manager); | |
| 75 | |
| 76 virtual void Downloading(App* app); | |
| 77 | |
| 78 virtual void DownloadComplete(App* app); | |
| 79 | |
| 80 virtual void MarkReadyToInstall(App* app); | |
| 81 | |
| 82 virtual void QueueInstall(App* app); | |
| 83 | |
| 84 virtual void Install(App* app, InstallManagerInterface* install_manager); | |
| 85 | |
| 86 virtual void Installing(App* app); | |
| 87 | |
| 88 virtual void ReportInstallerComplete(App* app, | |
| 89 const InstallerResultInfo& result_info); | |
| 90 | |
| 91 virtual void Pause(App* app); | |
| 92 | |
| 93 virtual void Cancel(App* app); | |
| 94 | |
| 95 virtual void Error(App* app, | |
| 96 const ErrorContext& error_context, | |
| 97 const CString& message); | |
| 98 | |
| 99 protected: | |
| 100 explicit AppState(CurrentState state) : state_(state) {} | |
| 101 | |
| 102 // After calling this method, the old state (this object) is deleted and the | |
| 103 // code may not reference the members of the old state anymore. | |
| 104 void ChangeState(App* app, AppState* app_state); | |
| 105 | |
| 106 void HandleInvalidStateTransition(App* app, const TCHAR* function_name); | |
| 107 | |
| 108 static PingEvent::Results GetCompletionResult(const App& app); | |
| 109 | |
| 110 private: | |
| 111 // TODO(omaha): rename to CurrentStateId or similar. | |
| 112 const CurrentState state_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(AppState); | |
| 115 }; | |
| 116 | |
| 117 } // namespace fsm | |
| 118 | |
| 119 } // namespace omaha | |
| 120 | |
| 121 #endif // OMAHA_GOOPDATE_APP_STATE_H_ | |
| OLD | NEW |