Implement Resource Class
authorJoonghyun Cho <jh5.cho@samsung.com>
Mon, 27 Apr 2015 06:21:57 +0000 (15:21 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Thu, 30 Apr 2015 07:09:58 +0000 (16:09 +0900)
 - change GetStartURL() to GetStartResource() which returns unique_ptr of Resource class
 - modify web_application.cc to match the changes of GetStartResource()

Change-Id: Ief2a396aa46d41f3682cbb12cdd986a35748d641

src/runtime/resource_manager.cc
src/runtime/resource_manager.h
src/runtime/web_application.cc

index 6880b99..6cf8e1a 100755 (executable)
@@ -156,6 +156,38 @@ static std::string InsertPrefixPath(const std::string& start_uri) {
 
 }  // namespace
 
+ResourceManager::Resource::Resource(const std::string& uri)
+  : uri_(uri), should_reset_(true) {}
+
+ResourceManager::Resource::Resource(const std::string& uri,
+                                    const std::string& mime)
+  : uri_(uri), mime_(mime), should_reset_(true) {}
+
+ResourceManager::Resource::Resource(const std::string& uri,
+                                    const std::string& mime, bool should_reset)
+  : uri_(uri), mime_(mime), should_reset_(should_reset) {}
+
+ResourceManager::Resource::Resource(const ResourceManager::Resource& res) {
+  *this = res;
+}
+
+ResourceManager::Resource& ResourceManager::Resource::operator=(
+    const ResourceManager::Resource& res) {
+  this->uri_ = res.uri();
+  this->mime_ = res.mime();
+  this->should_reset_ = res.should_reset();
+  return *this;
+}
+
+bool ResourceManager::Resource::operator==(const Resource& res) {
+  if (this->uri_ == res.uri() && this->mime_ == res.mime()
+     && this->should_reset_ == res.should_reset()) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
 ResourceManager::ResourceManager(ApplicationData* application_data,
                                  LocaleManager* locale_manager)
     : application_data_(application_data), locale_manager_(locale_manager) {
@@ -212,15 +244,16 @@ std::string ResourceManager::GetMatchedSrcOrUri(
   return GetDefaultOrEmpty();
 }
 
-std::string ResourceManager::GetStartURL() {
-  std::string operation = app_control_->operation();
+std::unique_ptr<ResourceManager::Resource> ResourceManager::GetStartResource(
+    const AppControl* app_control) {
+  std::string operation = app_control->operation();
   if (operation.empty()) {
     LoggerE("operation(mandatory) is NULL");
-    return GetDefaultOrEmpty();
+    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
   }
 
-  std::string mime = app_control_->mime();
-  std::string uri = app_control_->uri();
+  std::string mime = app_control->mime();
+  std::string uri = app_control->uri();
   if (mime.empty() && !uri.empty()) {
     mime = GetMimeFromUri(uri);
   }
@@ -232,7 +265,7 @@ std::string ResourceManager::GetStartURL() {
 
   if (application_data_ == NULL ||
       application_data_->app_control_info_list() == NULL) {
-    return GetDefaultOrEmpty();
+    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
   }
 
   AppControlList app_control_list =
@@ -243,12 +276,15 @@ std::string ResourceManager::GetStartURL() {
     AppControlList::const_iterator iter =
       CompareMimeAndUri(app_control_list, mime, uri);
     if (iter != app_control_list.end()) {
-      return GetMatchedSrcOrUri(*iter);
+      // TODO(jh5.cho) : following comment will be added after SRPOL implement
+      return std::unique_ptr<Resource>(
+        new Resource(GetMatchedSrcOrUri(*iter), iter->mime()
+                   /*, iter->should_reset()*/));
     } else {
-      return GetDefaultOrEmpty();
+    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
     }
   } else {
-    return GetDefaultOrEmpty();
+    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
   }
 }
 
index 9f05f06..884b659 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <string>
 #include <map>
+#include <memory>
 
 namespace wgt {
 
@@ -26,6 +27,32 @@ class AppControl;
 
 class ResourceManager {
  public:
+  class Resource {
+   public:
+    explicit Resource(const std::string& uri);
+    Resource(const std::string& uri, const std::string& mime);
+    Resource(const std::string& uri, const std::string& mime,
+             bool should_reset);
+    Resource(const Resource& res);
+    ~Resource() {}
+
+    Resource& operator=(const Resource& res);
+    bool operator==(const Resource& res);
+
+    void set_uri(const std::string& uri) { uri_ = uri; }
+    void set_mime(const std::string& mime) { mime_ = mime; }
+    void set_should_reset(bool should_reset) { should_reset_ = should_reset; }
+
+    std::string uri() const { return uri_; }
+    std::string mime() const { return mime_; }
+    bool should_reset() const { return should_reset_; }
+
+   private:
+    std::string uri_;
+    std::string mime_;
+    bool should_reset_;
+  };
+
   ResourceManager(ApplicationData* application_data,
                   LocaleManager* locale_manager);
   ~ResourceManager() {}
@@ -33,14 +60,9 @@ class ResourceManager {
   // input : file:///..... , app://[appid]/....
   // output : /[system path]/.../locales/.../
   std::string GetLocalizedPath(const std::string& origin);
-  std::string GetStartURL();
+  std::unique_ptr<Resource> GetStartResource(const AppControl* app_control);
 
   void set_base_resource_path(const std::string& base_path);
-  void set_app_control(AppControl* app_control) {
-    app_control_ = app_control;
-  }
-
-  const AppControl* app_control() const { return app_control_; }
 
  private:
   std::string GetMatchedSrcOrUri(const wgt::parse::AppControlInfo&);
@@ -55,7 +77,6 @@ class ResourceManager {
 
   ApplicationData* application_data_;
   LocaleManager* locale_manager_;
-  AppControl* app_control_;
 };
 
 }  // namespace wrt
index 72bd68d..7ffb539 100755 (executable)
@@ -168,7 +168,6 @@ bool WebApplication::Initialize() {
 }
 
 void WebApplication::Launch(std::unique_ptr<wrt::AppControl> appcontrol) {
-  resource_manager_->set_app_control(appcontrol.get());
   WebView* view = new WebView(window_, ewk_context_);
   SetupWebView(view);
 
@@ -183,8 +182,9 @@ void WebApplication::Launch(std::unique_ptr<wrt::AppControl> appcontrol) {
 
   // view->LoadUrl("file:///home/owner/apps_rw/33CFo0eFJe/"
   //               "33CFo0eFJe.annex/index.html");
-  view->LoadUrl(resource_manager_->GetStartURL());
-
+  std::unique_ptr<ResourceManager::Resource> res =
+    resource_manager_->GetStartResource(appcontrol.get());
+  view->LoadUrl(res->uri());
   view_stack_.push_front(view);
   window_->SetContent(view->evas_object());
 
@@ -215,15 +215,16 @@ void WebApplication::Launch(std::unique_ptr<wrt::AppControl> appcontrol) {
 
 void WebApplication::AppControl(std::unique_ptr<wrt::AppControl> appcontrol) {
   // TODO(sngn.lee): Set the injected bundle into extension process
-  resource_manager_->set_app_control(appcontrol.get());
 
-  if (true) {
+  std::unique_ptr<ResourceManager::Resource> res =
+    resource_manager_->GetStartResource(appcontrol.get());
+  if (res->should_reset()) {
     // Reset to context
     ClearViewStack();
     WebView* view = new WebView(window_, ewk_context_);
     SetupWebView(view);
 
-    view->LoadUrl(resource_manager_->GetStartURL());
+    view->LoadUrl(res->uri());
     view_stack_.push_front(view);
     window_->SetContent(view->evas_object());
   } else {