[NextBrowser] DataSync Backend Functionality Implementation 44/315344/30
authorjmroman <jm.roman@samsung.com>
Tue, 30 Jul 2024 09:37:05 +0000 (17:37 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 10 Sep 2024 05:43:14 +0000 (05:43 +0000)
Change-Id: I5d2d5f391039495475c4963d99495f4a89562c24
Signed-off-by: jmroman <jm.roman@samsung.com>
41 files changed:
chrome/browser/ui/BUILD.gn
chrome/browser/ui/samsung/data_sync_controller.cc [new file with mode: 0644]
chrome/browser/ui/samsung/data_sync_controller.h [new file with mode: 0644]
chrome/browser/ui/samsung/samsung_browser_core.cc
chrome/browser/ui/samsung/samsung_browser_core.h
chrome/browser/ui/samsung/storage_manager.cc
chrome/browser/ui/samsung/storage_manager.h
components/samsung/bptab_image_model/BUILD.gn [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_bptab_image_model.cc [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_bptab_image_model.h [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_history_id.h [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_history_item.h [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_iimage_model.h [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_image.h [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_image_tools.cc [new file with mode: 0644]
components/samsung/bptab_image_model/samsung_image_tools.h [new file with mode: 0644]
components/samsung/data_sync_service/BUILD.gn [new file with mode: 0644]
components/samsung/data_sync_service/data_sync_service_impl.cc [new file with mode: 0644]
components/samsung/data_sync_service/data_sync_service_impl.h [new file with mode: 0644]
components/samsung/opened_tabs/BUILD.gn [new file with mode: 0644]
components/samsung/opened_tabs/account_model.h [new file with mode: 0644]
components/samsung/opened_tabs/iaccount_model.h [new file with mode: 0644]
components/samsung/opened_tabs/opened_tab_id.h [new file with mode: 0644]
components/samsung/opened_tabs/opened_tab_item.cc [new file with mode: 0644]
components/samsung/opened_tabs/opened_tab_item.h [new file with mode: 0644]
components/samsung/opened_tabs/opened_tab_model.cc [new file with mode: 0644]
components/samsung/opened_tabs/opened_tab_model.h [new file with mode: 0644]
components/samsung/opened_tabs/tab_id_store.h [new file with mode: 0644]
components/samsung/public/account_manager/samsung_image_tools_observer.h [new file with mode: 0644]
components/samsung/public/data_sync_service/data_sync_service.cc [new file with mode: 0644]
components/samsung/public/data_sync_service/data_sync_service.h [new file with mode: 0644]
components/samsung/public/samsung_browser_enums.h
components/samsung/samsung_cloud/libsamsungcloud.so [new file with mode: 0644]
components/samsung/samsung_cloud/samsung_cloud.h [new file with mode: 0644]
components/samsung/samsung_cloud/samsung_cloud_error.h [new file with mode: 0644]
components/samsung/samsung_cloud/samsung_cloud_service.h [new file with mode: 0644]
packaging/chromium-efl.spec
packaging/org.tizen.next-browser.xml.in
tizen_src/build/BUILD.gn
tizen_src/build/build_next_browser_tpk.sh
tizen_src/ewk/efl_integration/BUILD.gn

index 17d3a24f900cfaa37431b308c36b7ba5368711b6..693bd664f503cad3401120fae19f13af3d42c951 100644 (file)
@@ -694,14 +694,21 @@ static_library("ui") {
       "//components/samsung/input_provider",
       "//components/samsung/system_configuration",
       "//components/samsung/cursor_provider",
+      "//components/samsung/opened_tabs",
       "//components/samsung/storage_manager",
+      "//components/samsung/bptab_image_model",
       "//components/samsung/account_provider",
       "//components/samsung/samsung_pass",
+      "//components/samsung/data_sync_service",
     ]
 
     configs += [
     "//tizen_src/build:VDCurl",
     "//tizen_src/build:libVDCurl",
+    "//tizen_src/build:capi-cloud-tab",
+    "//tizen_src/build:libcapi-cloud-tab",
+    "//tizen_src/build:capi-media-image-util",
+    "//tizen_src/build:libcapi-media-image-util",
     ]
   }
   # TODO(crbug.com/925153): Remove this circular dependency.
@@ -6682,6 +6689,8 @@ static_library("ui") {
         "samsung/samsung_account_manager.h",
         "samsung/high_contrast_controller.cc",
         "samsung/high_contrast_controller.h",
+        "samsung/data_sync_controller.cc",
+        "samsung/data_sync_controller.h",
       ]
     }
   }
@@ -6893,3 +6902,5 @@ if (is_android) {
     sources = [ "android/toolbar/adaptive_toolbar_enums.h" ]
   }
 }
+
+
diff --git a/chrome/browser/ui/samsung/data_sync_controller.cc b/chrome/browser/ui/samsung/data_sync_controller.cc
new file mode 100644 (file)
index 0000000..2795098
--- /dev/null
@@ -0,0 +1,192 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/samsung/data_sync_controller.h"
+#include "base/task/task_runner.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/samsung/samsung_browser_core.h"
+
+namespace samsung_browser_controller {
+
+constexpr int SYNC_TIMER_DELAY_FOR_HIGH_END = 5;
+constexpr int SYNC_TIMER_DELAY_FOR_LOW_END = 8;
+
+DataSyncController::DataSyncController(Browser* browser)
+    : browser_(browser),
+      m_isInitialized(false),
+      m_wasUserLogged(-1),
+      m_prevUserName(""),
+      m_isSyncEnabled(false),
+      m_syncTimerDelay(SYNC_TIMER_DELAY_FOR_HIGH_END),
+      m_cancelled_timer(false),
+      m_data_sync_service(nullptr) {
+  LOG(INFO) << "Constructor start";
+}
+
+DataSyncController::~DataSyncController() {
+  LOG(INFO) << "Destructor start";
+  // task
+  DeInit();
+}
+
+bool DataSyncController::Init() {
+  LOG(INFO) << "DataSyncController::Init()";
+  auto core = samsung_browser_main::SamsungBrowserCore::instance();
+  if (!core) {
+    LOG(ERROR) << "DataSyncController::Init() BrowserCore is null";
+    return false;
+  }
+
+  m_data_sync_service =
+      std::make_unique<samsung_browser_service::DataSyncService>();
+  if (m_data_sync_service->Init()) {
+    LOG(INFO) << "samsung_browser_service::DataSyncService init called";
+  }
+
+  // TODO: dynamically set timer delay based on preloading level
+  // FOR NOW: will currently default to low end
+
+  // if(preloadingLevel < 2)
+  if (true) {
+    m_syncTimerDelay = SYNC_TIMER_DELAY_FOR_LOW_END;
+  }
+
+  // BrowserConfig->autmaticSynchronizationChanged
+  // TODO: add an observer and callback to sync changed once implemented
+  // FOR NOW: will assume sync change is always true;
+
+  // auto brwsConfig =
+  // samsung_browser_main::SamsungBrowserCore::instance()->browserConfiguration();
+  // if (!brwsConfig)
+  // {
+  //   BROWSER_LOGW("No browser configuration");
+  //   return false;
+  // }
+
+  // m_isSyncEnabled =
+  // BrowserConfig->getBool(BrowserFWCore::ConfigKey::AutomaticSynchronization);
+  m_isSyncEnabled = true;
+
+  // AccountManager migrated to SamsungAccountService (pending implementation)
+  // TODO: update to check SamsungAccountServince once implemented
+  // FOR NOW: will assume user is logged on
+
+  // if(SamsungAccountService->isUserLogged()) {
+  if (true) {
+    startSyncTimer();
+  }
+
+  // bool isUserLogged = SamsungAccountService->isUserLogged();
+  bool isUserLogged = true;
+  if (isUserLoginStateChanged(isUserLogged)) {
+    if (isUserLogged) {
+      userLoggedIn();
+    } else {
+      userLoggedOut();
+    }
+  }
+
+  m_isInitialized = true;
+
+  LOG(INFO) << "DataSyncController::Init() done";
+  return true;
+}
+
+void DataSyncController::DeInit() {
+  LOG(INFO) << "DataSyncController::DeInit()";
+  return;
+}
+
+bool DataSyncController::isUserLoginStateChanged(bool isUserLogged) {
+  LOG(INFO) << "DataSyncController::isUserLoginStateChanged";
+  bool loginStateChanged = true;
+  if (m_wasUserLogged != -1) {
+    bool wasLogged = static_cast<bool>(m_wasUserLogged);
+
+    // AccountManager migrated to SamsungAccountService (pending implementation)
+    // TODO: update to check SamsungAccountServince once implemented
+    // FOR NOW: will assume user is logged on
+    loginStateChanged =
+        (wasLogged != isUserLogged);  // || (m_prevUserName !=
+                                      // SamsungAccountService->getLoginID());
+  }
+
+  LOG(INFO) << "DataSyncController::isUserLoginStateChanged done";
+  return loginStateChanged;
+}
+
+void DataSyncController::userLoggedIn() {
+  LOG(INFO) << "DataSyncController::userLoggedIn()";
+  m_wasUserLogged = 1;
+
+  // AccountManager migrated to SamsungAccountService (pending implementation)
+  // TODO: update to check SamsungAccountServince once implemented
+  // FOR NOW: will assume user is logged on as John Does
+
+  // m_prevUserName = SamsungAccountService->getLoginID();
+  m_prevUserName = "JohnDoe";
+}
+void DataSyncController::userLoggedOut() {
+  LOG(INFO) << "DataSyncController::userLoggedOut()";
+  m_wasUserLogged = 0;
+  m_prevUserName = "";
+
+  auto core = samsung_browser_main::SamsungBrowserCore::instance();
+  if (!core) {
+    LOG(ERROR) << "DataSyncController::userLoggedOut() BrowserCore is null";
+    return;
+  }
+
+  m_data_sync_service->enableAdaptersAutoSync(false);
+  endSyncTimer();
+}
+void DataSyncController::autoSyncChanged(bool) {
+  // TODO: Implement in the future once BrowserConfig has been implemented
+  return;
+}
+
+void DataSyncController::endSyncTimer() {
+  m_cancelled_timer = true;
+  return;
+}
+
+void DataSyncController::syncTimerCallback() {
+  LOG(INFO) << "DataSyncController::syncTimerCallback()";
+
+  auto core = samsung_browser_main::SamsungBrowserCore::instance();
+  if (!core) {
+    LOG(ERROR) << "DataSyncController::syncTimerCallback() BrowserCore is null";
+    return;
+  }
+
+  if (!m_cancelled_timer) {
+    m_data_sync_service->enableAdaptersAutoSync(m_isSyncEnabled);
+  }
+  m_cancelled_timer = false;
+}
+
+void DataSyncController::startSyncTimer() {
+  LOG(INFO) << "DataSyncController::startSyncTimer()";
+  endSyncTimer();
+
+  if (m_isSyncEnabled) {
+    m_cancelled_timer = false;
+    base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
+        FROM_HERE,
+        base::BindOnce(&DataSyncController::syncTimerCallback,
+                       base::Unretained(this)),
+        base::Seconds(m_syncTimerDelay));
+  } else {
+    auto core = samsung_browser_main::SamsungBrowserCore::instance();
+    if (!core) {
+      LOG(ERROR) << "DataSyncController::startSyncTimer() BrowserCore is null";
+      return;
+    }
+
+    m_data_sync_service->enableAdaptersAutoSync(m_isSyncEnabled);
+    m_cancelled_timer = false;
+  }
+}
+
+}  // namespace samsung_browser_controller
\ No newline at end of file
diff --git a/chrome/browser/ui/samsung/data_sync_controller.h b/chrome/browser/ui/samsung/data_sync_controller.h
new file mode 100644 (file)
index 0000000..fe7d1c5
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_SAMSUNG_DATA_SYNC_CONTROLLER_H_
+#define CHROME_BROWSER_UI_SAMSUNG_DATA_SYNC_CONTROLLER_H_
+
+#include "base/task/cancelable_task_tracker.h"
+#include "chrome/browser/ui/browser.h"
+#include "components/samsung/public/data_sync_service/data_sync_service.h"
+
+namespace samsung_browser_controller {
+
+class DataSyncController {
+ public:
+  explicit DataSyncController(Browser* browser);
+  ~DataSyncController();
+  DataSyncController(const DataSyncController&) = delete;
+  DataSyncController& operator=(const DataSyncController&) = delete;
+
+  bool Init();
+  void DeInit();
+
+ private:
+  // void browserStateChanged(BrowserMain::BrowserCore::BrowserState);
+  // void onWindowVisibilityChanged(int state);
+  // bool activate();                                 moved to init
+  bool isUserLoginStateChanged(bool isUserLogged);
+  // void deactivate();                               moved to deinit
+  void userLoggedIn();
+  void userLoggedOut();
+  void autoSyncChanged(bool);
+  void startSyncTimer();
+  void endSyncTimer();
+  // void onsvcUpdateStarted();
+  // void onsvcUpdateCompleted();
+  // static Eina_Bool syncTimerCallback(void*);       move to TaskDelay
+  void syncTimerCallback();
+
+  raw_ptr<Browser> browser_;
+  base::CancelableTaskTracker m_cancelable_task_tracker;
+  bool m_isInitialized;
+  // bool m_isActive;                                 merging with
+  // m_isinitialized
+  int m_wasUserLogged;  // -1 didn't even check, 0 - user was not logged, 1 -
+                        // user was logged
+  std::string m_prevUserName;
+  // Ecore_Timer* m_syncTimerHandler;                move to TaskDelay
+  bool m_isSyncEnabled;
+  bool m_cancelled_timer;
+  int m_syncTimerDelay;
+  // base::WeakPtrFactory<DataSyncController>(this);
+  std::unique_ptr<samsung_browser_service::DataSyncService> m_data_sync_service;
+};
+}  // namespace samsung_browser_controller
+
+#endif  // CHROME_BROWSER_UI_SAMSUNG_DATA_SYNC_CONTROLLER_H_
\ No newline at end of file
index bb2885ebdaa04cc60a10dcec311e9eccaa2dc1e5..3bd03919c5690d272ebfef6831b7fd13769bd4e9 100644 (file)
 
 #include "base/logging.h"
 #include "chrome/browser/ui/browser_window.h"
+
+SamsungAbstractID SamsungAbstractID::NONE;
+namespace samsung_browser_fw_core {
+samsung_browser_fw_core::OpenedTabID samsung_browser_fw_core::OpenedTabID::NONE;
+}
+
 namespace samsung_browser_main {
 
 SamsungBrowserCore* SamsungBrowserCore::m_instance = nullptr;
@@ -20,8 +26,8 @@ SamsungBrowserCore::SamsungBrowserCore()
       m_system_configuration_(nullptr),
       m_hybrid_navigation_controller(nullptr),
       m_high_contrast_controller(nullptr),
-      m_samsung_account_manager(nullptr),
       m_samsung_pass(nullptr) {}
+m_data_sync_controller(nullptr), m_samsung_account_manager(nullptr) {}
 
 SamsungBrowserCore* SamsungBrowserCore::instance() {
   if (!m_instance) {
@@ -32,6 +38,7 @@ SamsungBrowserCore* SamsungBrowserCore::instance() {
 }
 
 void SamsungBrowserCore::Init() {
+  LOG(INFO) << "SamsungBrowserCore::Init() ";
   SetWindowInstance();
   SetAccountManagerInstance();
   m_input_manager = std::make_unique<samsung_input_manager::InputManager>();
@@ -65,6 +72,10 @@ void SamsungBrowserCore::Init() {
 
   m_samsung_pass = std::make_unique<SamsungPass>();
   m_samsung_pass->Init();
+  m_data_sync_controller =
+      std::make_unique<samsung_browser_controller::DataSyncController>(
+          browser_);
+  m_data_sync_controller->Init();
 }
 
 SamsungBrowserCore::~SamsungBrowserCore() {}
index ea5e95f86123634954a9de6712abfdec4c2409bf..a57d605e0c7f931e4fd037cd3c30beb212b8e226 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/samsung/cursor_controller.h"
+#include "chrome/browser/ui/samsung/data_sync_controller.h"
 #include "chrome/browser/ui/samsung/high_contrast_controller.h"
 #include "chrome/browser/ui/samsung/hybrid_navigation_controller.h"
 #include "chrome/browser/ui/samsung/input_manager.h"
@@ -26,13 +27,16 @@ class SamsungBrowserCore {
   samsung_input_manager::InputManager* InputManager() {
     return m_input_manager.get();
   };
+
   samsung_browser_controller::CursorController* CursorController() {
     return m_cursor_controller.get();
   };
+
   samsung_browser_controller::HybridNavigationController*
   HybridNavigationController() {
     return m_hybrid_navigation_controller.get();
   };
+
   samsung_browser_configuration::SystemConfiguration* SystemConfiguration() {
     return m_system_configuration_.get();
   };
@@ -41,11 +45,15 @@ class SamsungBrowserCore {
   }
   samsung_browser_fw_core::StorageManager* StorageManager() {
     return m_storage_manager_.get();
-  }
+  };
 
   samsung_browser_controller::HighContrastController* HighContrastController() {
     return m_high_contrast_controller.get();
-  }
+  };
+
+  samsung_browser_controller::DataSyncController* DataSyncController() {
+    return m_data_sync_controller.get();
+  };
 
   SamsungPass* GetSamsungPass() { return m_samsung_pass.get(); }
 
@@ -63,6 +71,8 @@ class SamsungBrowserCore {
   std::unique_ptr<samsung_browser_fw_core::SamsungWebServerDownloader>
       m_samsung_web_server_downloader;
   std::unique_ptr<samsung_input_manager::InputManager> m_input_manager;
+  std::unique_ptr<samsung_browser_controller::DataSyncController>
+      m_data_sync_controller;
   std::unique_ptr<samsung_browser_configuration::SystemConfiguration>
       m_system_configuration_;
   std::unique_ptr<samsung_browser_controller::CursorController>
@@ -79,4 +89,6 @@ class SamsungBrowserCore {
   aura::WindowTreeHost* window_host;
 };
 }  // namespace samsung_browser_main
+
+// namespace samsung_browser_main
 #endif  // CHROME_BROWSER_UI_SAMSUNG_SAMSUNG_BROWSER_CORE_H
index 80f8deeee4c04faf5f8bfef9a99e4d9f48442eb9..4562a9c0a78ace60786bb36b0efce9931801649c 100644 (file)
@@ -42,6 +42,24 @@ bool StorageManager::init(bool forceRestore) {
     return false;
   }
 
+  m_openedTabModel =
+      std::make_unique<samsung_browser_storage::BPOpenedTabModel>();
+  if (m_openedTabModel) {
+    m_openedTabModel->init();
+    LOG(INFO) << "Opened Tab Model Initialized";
+  } else {
+    LOG(INFO) << "Opened Tab Model Initialize Fail";
+  }
+
+  m_tabImageModel =
+      std::make_unique<samsung_browser_storage::BPTabImageModel>();
+  if (m_tabImageModel) {
+    m_tabImageModel->init();
+    LOG(INFO) << "Opened Tab Image Model Initialized";
+  } else {
+    LOG(INFO) << "Opened Tab Image Model Initialize Fail";
+  }
+
   m_initialized = true;
   return true;
 }
@@ -54,4 +72,24 @@ void StorageManager::deinit() {
   }
 }
 
+std::unique_ptr<samsung_browser_storage::BPOpenedTabModel>&
+StorageManager::openedTabModel() {
+  if (!m_openedTabModel) {
+    m_openedTabModel =
+        std::make_unique<samsung_browser_storage::BPOpenedTabModel>();
+    m_openedTabModel->init();
+  }
+  return m_openedTabModel;
+}
+
+std::unique_ptr<samsung_browser_storage::BPTabImageModel>&
+StorageManager::tabImageModel() {
+  if (!m_tabImageModel) {
+    m_tabImageModel =
+        std::make_unique<samsung_browser_storage::BPTabImageModel>();
+    m_tabImageModel->init();
+  }
+  return m_tabImageModel;
+}
+
 }  // namespace samsung_browser_fw_core
\ No newline at end of file
index 0300a4f347870129249ba2ea20b58b3ddc182eb1..5ceb7a181fb34a9acfd99ae4b6719e043bed3b5a 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef CHROME_BROWSER_UI_SAMSUNG_STORAGE_MANAGER_H
 #define CHROME_BROWSER_UI_SAMSUNG_STORAGE_MANAGER_H
 
+#include "components/samsung/bptab_image_model/samsung_bptab_image_model.h"
+#include "components/samsung/opened_tabs/opened_tab_model.h"
 #include "components/samsung/public/samsung_enums.h"
 #include "components/samsung/storage_manager/samsung_ifeatured_model.h"
 #include "components/samsung/storage_manager/samsung_model_info.h"
@@ -24,6 +26,14 @@ class StorageManager {
 
   std::unique_ptr<IFeaturedModel> m_featuredModel;
 
+  std::unique_ptr<samsung_browser_storage::BPOpenedTabModel>& openedTabModel();
+
+  std::unique_ptr<samsung_browser_storage::BPTabImageModel>& tabImageModel();
+
+  std::unique_ptr<samsung_browser_storage::BPOpenedTabModel> m_openedTabModel;
+
+  std::unique_ptr<samsung_browser_storage::BPTabImageModel> m_tabImageModel;
+
   static ModelInfo ImageFeatured;
 
   bool m_initialized;
diff --git a/components/samsung/bptab_image_model/BUILD.gn b/components/samsung/bptab_image_model/BUILD.gn
new file mode 100644 (file)
index 0000000..8a5b6a3
--- /dev/null
@@ -0,0 +1,25 @@
+source_set("bptab_image_model") {
+  sources = [
+    "samsung_bptab_image_model.cc",
+    "samsung_bptab_image_model.h",
+    "samsung_history_item.h",
+    "samsung_history_id.h",
+    "samsung_iimage_model.h",
+    "samsung_image_tools.cc",
+    "samsung_image_tools.h",
+    "samsung_image.h",
+  ]
+
+  deps = [
+    "//skia",
+  ]
+
+  public_deps = [ "//base", ]
+
+  configs += [
+    "//tizen_src/build:capi-cloud-tab",
+    "//tizen_src/build:libcapi-cloud-tab",
+    "//tizen_src/build:capi-media-image-util",
+    "//tizen_src/build:libcapi-media-image-util",
+  ]
+}
diff --git a/components/samsung/bptab_image_model/samsung_bptab_image_model.cc b/components/samsung/bptab_image_model/samsung_bptab_image_model.cc
new file mode 100644 (file)
index 0000000..76bd5a7
--- /dev/null
@@ -0,0 +1,260 @@
+#include "samsung_bptab_image_model.h"
+
+#include "base/logging.h"
+#include "chrome/browser/ui/samsung/samsung_browser_core.h"
+#include "components/samsung/bptab_image_model/samsung_image_tools.h"
+
+namespace samsung_browser_storage {
+
+std::string BPTabImageModel::sourceName = "BPTabImageModel";
+
+BPTabImageModel::BPTabImageModel() : m_initialized(false) {
+  LOG(INFO) << "";
+}
+
+BPTabImageModel::~BPTabImageModel() {
+  LOG(INFO) << "albrimon: ";
+  if (m_initialized) {
+    deinit();
+  }
+}
+
+bool BPTabImageModel::init() {
+  LOG(INFO) << "albrimon: ";
+
+  m_initialized = true;
+  return true;
+}
+
+void BPTabImageModel::deinit() {
+  m_initialized = false;
+}
+
+std::shared_ptr<samsung_browser_fw_core::Image> BPTabImageModel::getImage(
+    const std::string& url,
+    samsung_browser_fw_core::Image::ImageType type,
+    const std::string& source) const {
+  LOG(INFO) << "";
+  auto image = std::make_shared<samsung_browser_fw_core::Image>();
+
+  int* ids = NULL;
+  int ids_count = -1;
+  int id = 0;
+  int length = 0;
+  unsigned char* value = NULL;
+
+  if (tab_adaptor_get_id_list_by_keyword(
+          &ids, &ids_count, -1, 0, TAB_PROPERTY_DATE_CREATED, 0,
+          TAB_PROPERTY_URL, url.c_str(), 0) != 0) {
+    LOG(WARNING) << ("Cannot get duplicated ids");
+    LOG(WARNING) << ("Cannot get duplicated ids");
+    return image;
+  }
+  LOG(INFO) << ids_count;
+  if (ids_count <= 0 || !ids) {
+    LOG(WARNING) << ("Didn't find id with this url");
+    LOG(WARNING) << ("albrimon: Didn't find id with this url");
+    return image;
+  }
+
+  id = ids[0];
+
+  if (type == samsung_browser_fw_core::Image::ImageType::Thumb) {
+    int width = 0;
+    int height = 0;
+    if (tab_adaptor_get_snapshot(id, &width, &height, &value, &length) != 0) {
+      LOG(WARNING) << ("Cannot get snapshot");
+      LOG(WARNING) << ("albrimon: Cannot get snapshot");
+      free(ids);
+      return image;
+    }
+  } else if (type == samsung_browser_fw_core::Image::ImageType::Favicon) {
+    if (tab_adaptor_get_icon_png(id, &value, &length) != 0) {
+      LOG(WARNING) << ("Cannot get icon");
+      LOG(WARNING) << ("albrimon: Cannot get icon");
+      free(ids);
+      return image;
+    }
+  }
+  if (value == NULL) {
+    free(ids);
+    LOG(WARNING) << ("albrimon: value null");
+    return image;
+  }
+  image->data = (void*)value;
+  image->dataSize = length;
+  image->type = type;
+
+  LOG(INFO) << "length " << length;
+  free(ids);
+  return image;
+}
+
+bool BPTabImageModel::setImage(
+    const std::shared_ptr<samsung_browser_fw_core::Image> image,
+    const std::string& url,
+    const std::string& source) {
+  LOG(INFO) << "";
+  int* ids = NULL;
+  int ids_count = -1;
+  int id = 0;
+  if (tab_adaptor_get_id_list_by_keyword(
+          &ids, &ids_count, -1, 0, TAB_PROPERTY_DATE_CREATED, 0,
+          TAB_PROPERTY_URL, url.c_str(), 0) != 0) {
+    LOG(WARNING) << "Cannot get duplicated ids";
+    return false;
+  }
+  LOG(INFO) << ids_count;
+  if (ids_count <= 0 || !ids) {
+    LOG(WARNING) << "Didn't find id with this url";
+    return false;
+  }
+
+  id = ids[0];
+
+  void* blobImage;
+  int blobImageLength = 0;
+  if (image->isCompressed) {
+    blobImageLength = image->dataSize;
+    blobImage = malloc(blobImageLength);
+    if (blobImage)
+      memcpy(blobImage, image->data, blobImageLength);
+    else {
+      free(ids);
+      return false;
+    }
+  } else {
+    switch (image->type) {
+      case samsung_browser_fw_core::Image::ImageType::Favicon:
+        blobImage = samsung_browser_fw_core::ImageTools::pngCompressImage(
+            image->width, image->height, image->stride, image->data,
+            &blobImageLength);
+        break;
+
+      case samsung_browser_fw_core::Image::ImageType::Thumb:
+        blobImage = samsung_browser_fw_core::ImageTools::jpegCompressImage(
+            image->width, image->height, image->stride, image->data,
+            &blobImageLength);
+        break;
+      case samsung_browser_fw_core::Image::ImageType::UserIcon:
+      default:
+        LOG(WARNING) << "Wrong ImageType to save to DB. ImageType="
+                     << static_cast<int>(image->type);
+        free(ids);
+        return false;
+    }
+  }
+
+  if (image->type == samsung_browser_fw_core::Image::ImageType::Favicon) {
+    if (tab_adaptor_set_icon_png(
+            id, static_cast<const unsigned char*>(blobImage)) != 0) {
+      LOG(WARNING) << "Cannot set icon";
+      free(ids);
+      free(blobImage);
+      return false;
+    }
+  } else if (image->type == samsung_browser_fw_core::Image::ImageType::Thumb) {
+    if (tab_adaptor_set_snapshot(id, image->width, image->height,
+                                 static_cast<const unsigned char*>(blobImage),
+                                 image->dataSize) != 0) {
+      LOG(WARNING) << "ERROR returned by tab_adaptor_set_snapshot";
+      free(ids);
+      free(blobImage);
+      return false;
+    }
+  }
+  free(ids);
+  free(blobImage);
+  return true;
+}
+
+bool BPTabImageModel::removeImage(
+    const std::string& url,
+    samsung_browser_fw_core::Image::ImageType type,
+    const std::string& source) {
+  LOG(INFO) << "";
+  int* ids = NULL;
+  int ids_count = -1;
+  int id;
+  const unsigned char* emptyImage = nullptr;
+  if (tab_adaptor_get_id_list_by_keyword(
+          &ids, &ids_count, -1, 0, TAB_PROPERTY_DATE_CREATED, 0,
+          TAB_PROPERTY_URL, url.c_str(), 0) != 0) {
+    LOG(WARNING) << "Cannot get duplicated ids";
+    if (ids) {
+      free(ids);
+    }
+    return false;
+  }
+  LOG(INFO) << ids_count;
+  if (ids_count <= 0 || !ids) {
+    LOG(WARNING) << "Didn't find id with this url";
+    return false;
+  }
+
+  id = ids[0];
+  if (type == samsung_browser_fw_core::Image::ImageType::Favicon) {
+    if (tab_adaptor_set_icon_png(id, emptyImage) != 0) {
+      LOG(WARNING) << "Cannot set icon";
+      free(ids);
+      return false;
+    }
+  } else if (type == samsung_browser_fw_core::Image::ImageType::Thumb) {
+    if (tab_adaptor_set_snapshot(id, 0, 0, emptyImage, 0) != 0) {
+      LOG(WARNING) << "Cannot set snapshot";
+      free(ids);
+      return false;
+    }
+  }
+  free(ids);
+  return true;
+}
+bool BPTabImageModel::removeUnlinkedAccounts(
+    const std::vector<std::string>& linkedAccounts) {
+  LOG(INFO) << "";
+  return true;
+}
+void BPTabImageModel::cleanUp(
+    const std::vector<samsung_browser_fw_core::HistoryItem>& historyItems) {
+  LOG(WARNING) << "Not implemented";
+}
+
+bool BPTabImageModel::removeAllImages(
+    samsung_browser_fw_core::Image::ImageType type,
+    const std::string& source) {
+  LOG(INFO) << "";
+  int* ids = NULL;
+  int ids_count = -1;
+  const unsigned char* emptyImage = nullptr;
+
+  if (tab_adaptor_get_full_id_list(&ids, &ids_count) != 0) {
+    LOG(WARNING) << "Cannot get full ids";
+    if (ids) {
+      free(ids);
+    }
+    return false;
+  }
+  if (ids_count <= 0 || !ids) {
+    LOG(WARNING) << "Didn't find id with this url";
+    return false;
+  }
+  for (int i = 0; i < ids_count; ++i) {
+    if (type == samsung_browser_fw_core::Image::ImageType::Favicon) {
+      if (tab_adaptor_set_icon_png(ids[i], emptyImage) != 0) {
+        LOG(WARNING) << "Cannot set icon";
+        free(ids);
+        return false;
+      }
+    } else if (type == samsung_browser_fw_core::Image::ImageType::Thumb) {
+      if (tab_adaptor_set_snapshot(ids[i], 0, 0, emptyImage, 0) != 0) {
+        LOG(WARNING) << "Cannot set snapshot";
+        free(ids);
+        return false;
+      }
+    }
+  }
+  free(ids);
+  return true;
+}
+
+}  // namespace samsung_browser_storage
diff --git a/components/samsung/bptab_image_model/samsung_bptab_image_model.h b/components/samsung/bptab_image_model/samsung_bptab_image_model.h
new file mode 100644 (file)
index 0000000..8d68efe
--- /dev/null
@@ -0,0 +1,108 @@
+#ifndef COMPONENTS_SAMSUNG_BPTAB_TAB_IMAGE_MODEL_H
+#define COMPONENTS_SAMSUNG_BPTAB_TAB_IMAGE_MODEL_H
+
+#include <vector>
+// #include <web/web_tab.h>
+#include "cloud_tab.h"
+
+#include "components/samsung/bptab_image_model/samsung_iimage_model.h"
+#include "components/samsung/public/samsung_browser_enums.h"
+// #include "url/gurl.h"
+
+namespace samsung_browser_storage {
+
+class BPTabImageModel : public samsung_browser_fw_core::IImageModel {
+ public:
+  /**
+   * @brief
+   *
+   * @fn BPTabImageModel
+   */
+  BPTabImageModel();
+  /**
+   * @brief
+   *
+   * @fn ~BPTabImageModel
+   */
+  virtual ~BPTabImageModel();
+  /**
+   * @brief
+   *
+   * @fn init
+   * @return bool
+   */
+  bool init() override;
+  void deinit() override;
+
+  /**
+   * @brief
+   *
+   * @fn getImage
+   * @param url
+   * @param type
+   * @param source
+   * @return std::shared_ptr<samsung_browser_fw_core::Image>
+   */
+  std::shared_ptr<samsung_browser_fw_core::Image> getImage(
+      const std::string& url,
+      samsung_browser_fw_core::Image::ImageType type,
+      const std::string& source) const override;
+  /**
+   * @brief
+   *
+   * @fn setImage
+   * @param thumb
+   * @param url
+   * @param source
+   * @return bool
+   */
+  bool setImage(const std::shared_ptr<samsung_browser_fw_core::Image> image,
+                const std::string& url,
+                const std::string& source) override;
+  /**
+   * @brief
+   *
+   * @fn removeImage
+   * @param url
+   * @param type
+   * @param source
+   * @return bool
+   */
+  bool removeImage(const std::string& url,
+                   samsung_browser_fw_core::Image::ImageType type,
+                   const std::string& source) override;
+  bool removeUnlinkedAccounts(
+      const std::vector<std::string>& linkedAccounts) override;
+  /**
+   * @brief
+   *
+   * @fn cleanUp
+   * @param HistoryType
+   * @param source
+   */
+  void cleanUp(const std::vector<samsung_browser_fw_core::HistoryItem>&
+                   historyItems) override;
+  /**
+   * @brief
+   *
+   * @fn removeAllImages
+   * @param type
+   * @param source
+   * @return bool
+   */
+  bool removeAllImages(samsung_browser_fw_core::Image::ImageType type,
+                       const std::string& source) override;
+  /**
+   * @brief
+   *
+   * @var sourceName
+   */
+  static std::string sourceName;
+  bool m_initialized;
+
+ private:
+};
+
+}  // namespace samsung_browser_storage
+
+#endif  // BPTabImageModel_h
diff --git a/components/samsung/bptab_image_model/samsung_history_id.h b/components/samsung/bptab_image_model/samsung_history_id.h
new file mode 100644 (file)
index 0000000..d261ccf
--- /dev/null
@@ -0,0 +1,29 @@
+
+#ifndef COMPONENTS_BOOKMARK_SAMSUNG_BOOKMARK_HISTORY_ID_H_
+#define COMPONENTS_BOOKMARK_SAMSUNG_BOOKMARK_HISTORY_ID_H_
+
+#include "components/samsung/public/samsung_abstract_id.h"
+
+namespace samsung_browser_fw_core {
+
+/**
+ * @brief
+ *
+ * @class HistoryID HistoryID.h "include/HistoryID.h"
+ */
+class HistoryID : public SamsungAbstractID {
+ public:
+  HistoryID() : SamsungAbstractID() {}
+  /**
+   * @brief
+   *
+   * @fn HistoryID
+   * @param str
+   */
+  explicit HistoryID(const std::string& str) : SamsungAbstractID(str) {}
+
+  static HistoryID NONE;
+};
+
+}  // namespace samsung_browser_fw_core
+#endif  // HistoryID_h
\ No newline at end of file
diff --git a/components/samsung/bptab_image_model/samsung_history_item.h b/components/samsung/bptab_image_model/samsung_history_item.h
new file mode 100644 (file)
index 0000000..aee4b0e
--- /dev/null
@@ -0,0 +1,302 @@
+
+#ifndef COMPONENTS_SAMSUNG_BPTAB_HISTORY_ITEM_H
+#define COMPONENTS_SAMSUNG_BPTAB_HISTORY_ITEM_H
+
+#include "components/samsung/bptab_image_model/samsung_history_id.h"
+#include "components/samsung/public/samsung_browser_enums.h"
+// #include "url/gurl.h"
+
+#include <chrono>
+#include <ctime>
+
+namespace samsung_browser_fw_core {
+
+/**
+ * @brief
+ *
+ * @class HistoryItem HistoryItem.h "include/HistoryItem.h"
+ */
+class HistoryItem {
+ public:
+  HistoryItem();
+  explicit HistoryItem(HistoryID);
+  /**
+   * @brief
+   *
+   * @fn HistoryItem
+   * @param id
+   * @param url
+   * @param title
+   * @param source
+   * @param zoomLevel
+   * @param type
+   */
+  HistoryItem(const std::string& id,
+              const std::string& url,
+              const std::string& title,
+              const std::string& source,
+              int zoomLevel,
+              HistoryType type = HistoryType::UserHistory);
+  /**
+   * @brief
+   *
+   * @fn HistoryItem
+   * @param url
+   * @param title
+   * @param source
+   * @param zoomLevel
+   * @param type
+   */
+  HistoryItem(const std::string& url,
+              const std::string& title,
+              const std::string& source,
+              int zoomLevel,
+              HistoryType type = HistoryType::UserHistory);
+  /**
+   * @brief
+   *
+   * @fn HistoryItem
+   * @param
+   */
+  HistoryItem(const HistoryItem&);
+
+  /**
+   * @brief
+   *
+   * @fn ~HistoryItem
+   */
+  virtual ~HistoryItem();
+  /**
+   * @brief
+   *
+   * @fn operator =
+   * @param
+   * @return HistoryItem &operator
+   */
+  virtual HistoryItem& operator=(const HistoryItem&);
+  /**
+   * @brief
+   *
+   * @fn operator ==
+   * @param other
+   * @return bool operator
+   */
+  virtual bool operator==(const HistoryItem& other);
+  /**
+   * @brief
+   *
+   * @fn operator !=
+   * @param other
+   * @return bool operator
+   */
+  virtual bool operator!=(const HistoryItem& other);
+
+  /**
+   * @brief
+   *
+   * @fn setID
+   * @param id
+   */
+  virtual void setID(HistoryID id) { m_id = id; }
+  /**
+   * @brief
+   *
+   * @fn getID
+   * @return HistoryID
+   */
+  virtual HistoryID getID() const { return m_id; }
+
+  /**
+   * @brief
+   *
+   * @fn setURL
+   * @param url
+   */
+  virtual void setURL(const std::string& url) { m_url = url; }
+  /**
+   * @brief
+   *
+   * @fn getURL
+   * @return GURL
+   */
+  virtual std::string getURL() const { return m_url; }
+
+  /**
+   * @brief
+   *
+   * @fn setTitle
+   * @param title
+   */
+  virtual void setTitle(const std::string& title) { m_title = title; }
+  /**
+   * @brief
+   *
+   * @fn getTitle
+   * @return std::string
+   */
+  virtual std::string getTitle() const { return m_title; }
+
+  /**
+   * @brief
+   *
+   * @fn setCreationTime
+   * @param t
+   */
+  virtual void setCreationTime(
+      std::chrono::time_point<std::chrono::system_clock> t) {
+    m_creationTime = t;
+  }
+  /**
+   * @brief
+   *
+   * @fn getCreationTime
+   * @return std::chrono::time_point<std::chrono::system_clock>
+   */
+  virtual std::chrono::time_point<std::chrono::system_clock> getCreationTime()
+      const {
+    return m_creationTime;
+  }
+
+  /**
+   * @brief
+   *
+   * @fn setAccessTime
+   * @param t
+   */
+  virtual void setAccessTime(
+      std::chrono::time_point<std::chrono::system_clock> t) {
+    m_accessTime = t;
+  }
+  /**
+   * @brief
+   *
+   * @fn getAccessTime
+   * @return std::chrono::time_point<std::chrono::system_clock>
+   */
+  virtual std::chrono::time_point<std::chrono::system_clock> getAccessTime()
+      const {
+    return m_accessTime;
+  }
+
+  /**
+   * @brief
+   *
+   * @fn setSourceName
+   * @param src
+   */
+  virtual void setSourceName(const std::string& src) { m_sourceName = src; }
+  /**
+   * @brief
+   *
+   * @fn getSourceName
+   * @return std::string
+   */
+  virtual std::string getSourceName() const { return m_sourceName; }
+  /**
+   * @brief
+   *
+   * @fn setCounter
+   * @param counter
+   */
+  virtual void setCounter(int counter) { m_counter = counter; }
+  /**
+   * @brief
+   *
+   * @fn getCounter
+   * @return int
+   */
+  virtual int getCounter() const { return m_counter; }
+  /**
+   * @brief
+   *
+   * @fn setType
+   * @param type
+   */
+  virtual void setType(HistoryType type) { m_type = type; }
+  /**
+   * @brief
+   *
+   * @fn getType
+   * @return HistoryType
+   */
+  virtual HistoryType getType() const { return m_type; }
+  /**
+   * @brief
+   *
+   * @fn setZoomLevel
+   * @param zoomLevel
+   */
+  virtual void setZoomLevel(int zoomLevel) { m_zoomLevel = zoomLevel; }
+  /**
+   * @brief
+   *
+   * @fn getZoomLevel
+   * @return int
+   */
+  virtual int getZoomLevel() const { return m_zoomLevel; }
+  /**
+   * @brief
+   *
+   * @var INVALID
+   */
+  static HistoryItem INVALID;
+
+ private:
+  /**
+   * @brief
+   *
+   * @var m_id
+   */
+  HistoryID m_id;
+  /**
+   * @brief
+   *
+   * @var m_url
+   */
+  std::string m_url;
+  /**
+   * @brief
+   *
+   * @var m_title
+   */
+  std::string m_title;
+  /**
+   * @brief
+   *
+   * @var m_creationTime
+   */
+  std::chrono::time_point<std::chrono::system_clock> m_creationTime;
+  /**
+   * @brief
+   *
+   * @var m_accessTime
+   */
+  std::chrono::time_point<std::chrono::system_clock> m_accessTime;
+  /**
+   * @brief
+   *
+   * @var m_sourceName
+   */
+  std::string m_sourceName;
+  /**
+   * @brief
+   *
+   * @var m_counter
+   */
+  int m_counter;
+  /**
+   * @brief
+   *
+   * @var m_type
+   */
+  HistoryType m_type;
+  /**
+   * @brief
+   *
+   * @var m_zoomLevel
+   */
+  int m_zoomLevel;
+};
+
+}  // namespace samsung_browser_fw_core
+#endif  // HistoryItem_h
diff --git a/components/samsung/bptab_image_model/samsung_iimage_model.h b/components/samsung/bptab_image_model/samsung_iimage_model.h
new file mode 100644 (file)
index 0000000..c1d385d
--- /dev/null
@@ -0,0 +1,106 @@
+
+#ifndef COMPONENTS_SAMSUNG_BPTAB_IIMAGE_MODEL_H
+#define COMPONENTS_SAMSUNG_BPTAB_IIMAGE_MODEL_H
+
+#include "components/samsung/bptab_image_model/samsung_history_item.h"
+#include "components/samsung/bptab_image_model/samsung_image.h"
+#include "components/samsung/public/account_manager/samsung_image_tools_observer.h"
+#include "components/samsung/public/samsung_browser_enums.h"
+// #include "url/gurl.h"
+
+#include <memory>
+#include <string>
+
+namespace samsung_browser_fw_core {
+
+/**
+ * @brief
+ *
+ * @class IImageModel IImageModel.h "include/IImageModel.h"
+ */
+class IImageModel {
+ public:
+  /**
+   * @brief
+   *
+   * @fn ~IImageModel
+   */
+  virtual ~IImageModel() {}
+
+  /**
+   * @brief
+   *
+   * @fn init
+   * @return bool
+   */
+  virtual bool init() = 0;
+  /**
+   * @brief
+   *
+   * @fn deinit
+   * @return void
+   */
+  virtual void deinit() = 0;
+
+  /**
+   * @brief
+   *
+   * @fn getImage
+   * @param url
+   * @param type
+   * @param source
+   * @return std::shared_ptr<Image>
+   */
+  virtual std::shared_ptr<Image> getImage(
+      const std::string& url,
+      samsung_browser_fw_core::Image::ImageType type,
+      const std::string& source) const = 0;
+  /**
+   * @brief
+   *
+   * @fn setImage
+   * @param thumb
+   * @param url
+   * @param source
+   * @return bool
+   */
+  virtual bool setImage(const std::shared_ptr<Image> thumb,
+                        const std::string& url,
+                        const std::string& source) = 0;
+  /**
+   * @brief
+   *
+   * @fn removeImage
+   * @param url
+   * @param type
+   * @param source
+   * @return bool
+   */
+  virtual bool removeImage(const std::string& url,
+                           samsung_browser_fw_core::Image::ImageType type,
+                           const std::string& source) = 0;
+  /**
+   * @brief
+   *
+   * @fn cleanUp
+   * @param HistoryType
+   * @param source
+   */
+  virtual void cleanUp(const std::vector<samsung_browser_fw_core::HistoryItem>&
+                           historyItems) = 0;
+  /**
+   * @brief
+   *
+   * @fn removeAllImages
+   * @param type
+   * @param source
+   * @return bool
+   */
+  virtual bool removeAllImages(samsung_browser_fw_core::Image::ImageType type,
+                               const std::string& source) = 0;
+  virtual bool removeUnlinkedAccounts(const std::vector<std::string>&) = 0;
+};
+
+}  // namespace samsung_browser_fw_core
+
+#endif  // IImageModel_h
diff --git a/components/samsung/bptab_image_model/samsung_image.h b/components/samsung/bptab_image_model/samsung_image.h
new file mode 100644 (file)
index 0000000..de52bbd
--- /dev/null
@@ -0,0 +1,87 @@
+
+#ifndef COMPONENTS_SAMSUNG_BPTAB_IIMAGE_H
+#define COMPONENTS_SAMSUNG_BPTAB_IIMAGE_H
+
+#include <stdlib.h>
+
+namespace samsung_browser_fw_core {
+
+/**
+ * @brief
+ *
+ * @class Image Image.h "include/Image.h"
+ */
+struct Image {
+  /**
+   * @brief
+   *
+   * @enum ImageType
+   */
+  enum class ImageType {
+    Thumb = 1,
+    Favicon = 2,
+    UserIcon = 3,
+    Thumb4K = 4,
+  };
+  /**
+   * @brief
+   *
+   * @var data
+   */
+  void* data;
+  /**
+   * @brief
+   *
+   * @var dataSize
+   */
+  int dataSize;
+  /**
+   * @brief
+   *
+   * @var width
+   */
+  int width;
+  /**
+   * @brief
+   *
+   * @var height
+   */
+  int height;
+  /**
+   * @brief
+   *
+   * @var stride
+   */
+  int stride;
+  /**
+   * @brief
+   *
+   * @var type
+   */
+  ImageType type;
+  /**
+   * @brief
+   *
+   * @var isCompressed
+   */
+  bool isCompressed;
+
+  Image()
+      : data(nullptr),
+        dataSize(0),
+        width(0),
+        height(0),
+        stride(0),
+        type(ImageType::Thumb),
+        isCompressed(false) {}
+  /**
+   * @brief
+   *
+   * @fn ~Image
+   */
+  ~Image() { free(data); }
+};
+
+}  // namespace samsung_browser_fw_core
+
+#endif  // Image_h
diff --git a/components/samsung/bptab_image_model/samsung_image_tools.cc b/components/samsung/bptab_image_model/samsung_image_tools.cc
new file mode 100644 (file)
index 0000000..1b631c1
--- /dev/null
@@ -0,0 +1,226 @@
+#include "components/samsung/bptab_image_model/samsung_image_tools.h"
+
+#include <image_util.h>
+#include <mutex>
+#include "base/logging.h"
+
+static std::mutex s_faviconsSavingLock;
+
+namespace samsung_browser_fw_core {
+
+void* ImageTools::pngCompressImage(int width,
+                                   int height,
+                                   int stride,
+                                   const void* imageData,
+                                   int* length,
+                                   int level) {
+  LOG(INFO) << "width[" << width << "], height[" << height << "], stride["
+            << stride << "]";
+
+  if (length) {
+    *length = 0;
+  }
+  if (width <= 0 || height <= 0 || stride <= 0) {
+    LOG(WARNING) << "Incorrect image";
+    return NULL;
+  }
+  if (!imageData) {
+    LOG(WARNING) << "imageData is null";
+    return NULL;
+  }
+
+  // Ref : DF211122-00543 : As per this defect mutex lock has been applied to
+  // pngCompressImage in ImageTools Prior to this, mutex lock was applied in
+  // FaviconController.cpp Ref : DF201119-00284, DF201120-00533: Sometimes
+  // favicons are updated very fast and hence db and image-util png compression
+  // are not ready image-util cant handle multiple threads for image compression
+  // and causes crash (png_write_row)
+
+  s_faviconsSavingLock.lock();
+  LOG(INFO) << "Locked";
+
+  int error = IMAGE_UTIL_ERROR_NONE;
+  image_util_image_h input_image = NULL;
+  image_util_encode_h image_handle = NULL;
+  unsigned char* image_buffer = NULL;
+  size_t image_buffer_size = 0;
+
+  do {
+    // Creating raw image
+    error =
+        image_util_create_image(width, height, IMAGE_UTIL_COLORSPACE_BGRA8888,
+                                static_cast<const unsigned char*>(imageData),
+                                (size_t)(height * stride), &input_image);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error creating image";
+      printError(error);
+      break;
+    }
+    // Compressing raw image
+    error = image_util_encode_create(IMAGE_UTIL_PNG, &image_handle);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error creating encode handle";
+      printError(error);
+      break;
+    }
+    error = image_util_encode_set_png_compression(
+        image_handle, static_cast<image_util_png_compression_e>(level));
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error setting compression";
+      printError(error);
+      break;
+    }
+    error = image_util_encode_run_to_buffer(image_handle, input_image,
+                                            &image_buffer, &image_buffer_size);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error during encoding";
+      printError(error);
+      break;
+    }
+  } while (0);
+
+  if (input_image) {
+    error = image_util_destroy_image(input_image);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error destroying image";
+      printError(error);
+    }
+    input_image = NULL;
+  }
+  if (image_handle) {
+    error = image_util_encode_destroy(image_handle);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error destroying encode handle";
+      printError(error);
+    }
+    image_handle = NULL;
+  }
+
+  LOG(INFO) << "PNG compressed from " << stride * height << " to "
+            << image_buffer_size << " bytes";
+
+  s_faviconsSavingLock.unlock();
+  LOG(INFO) << "Unlocked";
+
+  if (length) {
+    *length = (int)image_buffer_size;
+    if (*length <= 0) {
+      free(image_buffer);
+      return NULL;
+    }
+  }
+  return image_buffer;
+}
+
+void* ImageTools::jpegCompressImage(int width,
+                                    int height,
+                                    int stride,
+                                    const void* imageData,
+                                    int* length,
+                                    int quality) {
+  LOG(INFO) << "width[" << width << "], height[" << height << "], stride["
+            << stride << "]";
+
+  if (length) {
+    *length = 0;
+  }
+  if (width <= 0 || height <= 0 || stride <= 0) {
+    LOG(WARNING) << "Incorrect image";
+    return NULL;
+  }
+  if (!imageData) {
+    LOG(WARNING) << "imageData is null";
+    return NULL;
+  }
+
+  int error = IMAGE_UTIL_ERROR_NONE;
+  image_util_image_h input_image = NULL;
+  image_util_encode_h image_handle = NULL;
+  unsigned char* image_buffer = NULL;
+  size_t image_buffer_size = 0;
+
+  do {
+    // Creating raw image
+    error =
+        image_util_create_image(width, height, IMAGE_UTIL_COLORSPACE_BGRA8888,
+                                static_cast<const unsigned char*>(imageData),
+                                (size_t)(height * stride), &input_image);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error creating image";
+      printError(error);
+      break;
+    }
+    // Compressing raw image
+    error = image_util_encode_create(IMAGE_UTIL_JPEG, &image_handle);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error creating encode handle";
+      printError(error);
+      break;
+    }
+    error = image_util_encode_set_quality(image_handle, quality);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error setting quality";
+      printError(error);
+      break;
+    }
+    error = image_util_encode_run_to_buffer(image_handle, input_image,
+                                            &image_buffer, &image_buffer_size);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error during encoding";
+      printError(error);
+      break;
+    }
+  } while (0);
+
+  if (input_image) {
+    error = image_util_destroy_image(input_image);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error destroying image";
+      printError(error);
+    }
+    input_image = NULL;
+  }
+  if (image_handle) {
+    error = image_util_encode_destroy(image_handle);
+    if (error != IMAGE_UTIL_ERROR_NONE) {
+      LOG(WARNING) << "Error destroying encode handle";
+      printError(error);
+    }
+    image_handle = NULL;
+  }
+
+  LOG(INFO) << "JPEG compressed from " << stride * height << " to "
+            << image_buffer_size << " bytes";
+  if (length) {
+    *length = (int)image_buffer_size;
+    if (*length <= 0) {
+      free(image_buffer);
+      return NULL;
+    }
+  }
+  return image_buffer;
+}
+
+void ImageTools::printError(int error) {
+  switch (error) {
+    case IMAGE_UTIL_ERROR_NONE:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_NONE");
+                                 // break;
+    case IMAGE_UTIL_ERROR_INVALID_PARAMETER:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_INVALID_PARAMETER");
+                                              // break;
+    case IMAGE_UTIL_ERROR_OUT_OF_MEMORY:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_OUT_OF_MEMORY");
+                                          // break;
+    case IMAGE_UTIL_ERROR_NO_SUCH_FILE:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_NO_SUCH_FILE");
+                                         // break;
+    case IMAGE_UTIL_ERROR_INVALID_OPERATION:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_INVALID_OPERATION");
+                                              // break;
+    case IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT");break;
+    case IMAGE_UTIL_ERROR_PERMISSION_DENIED:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_PERMISSION_DENIED");
+                                              // break;
+    case IMAGE_UTIL_ERROR_NOT_SUPPORTED:  // BROWSER_LOGD("IMAGE_UTIL_ERROR_NOT_SUPPORTED");
+                                          // break;
+    default:
+      LOG(INFO) << "Default";
+  }
+}
+
+}  // namespace samsung_browser_fw_core
diff --git a/components/samsung/bptab_image_model/samsung_image_tools.h b/components/samsung/bptab_image_model/samsung_image_tools.h
new file mode 100644 (file)
index 0000000..e0a9560
--- /dev/null
@@ -0,0 +1,45 @@
+
+#ifndef COMPONENTS_SAMSUNG_BOOKMARK_IMAGE_TOOLS_H_
+#define COMPONENTS_SAMSUNG_BOOKMARK_IMAGE_TOOLS_H_
+
+namespace samsung_browser_fw_core {
+
+/**
+ * @brief
+ *
+ * @class ImageTools ImageTools.h "include/ImageTools.h"
+ */
+class ImageTools {
+ public:
+  /**
+   * @brief
+   *
+   * @fn pngCompressImage
+   * @param int
+   * @param int
+   * @param int
+   * @param
+   * @param
+   * @param int
+   */
+  static void* pngCompressImage(int, int, int, const void*, int*, int = 9);
+  /**
+   * @brief
+   *
+   * @fn jpegCompressImage
+   * @param int
+   * @param int
+   * @param int
+   * @param
+   * @param
+   * @param int
+   */
+  static void* jpegCompressImage(int, int, int, const void*, int*, int = 90);
+
+ private:
+  static void printError(int error);
+};
+
+}  // namespace samsung_browser_fw_core
+
+#endif  // ImageTools_h
diff --git a/components/samsung/data_sync_service/BUILD.gn b/components/samsung/data_sync_service/BUILD.gn
new file mode 100644 (file)
index 0000000..e225136
--- /dev/null
@@ -0,0 +1,43 @@
+# Copyright 2023 Samsung Electronics.All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("data_sync_service") {
+  sources = [
+    "../public/data_sync_service/data_sync_service.cc",
+    "../public/data_sync_service/data_sync_service.h",
+    "../samsung_cloud/samsung_cloud.h",
+    "../samsung_cloud/samsung_cloud_service.h",
+    "../samsung_cloud/samsung_cloud_error.h",
+    "data_sync_service_impl.cc",
+    "data_sync_service_impl.h",
+  ]
+
+  deps = [
+    "//skia",
+  ]
+
+  public_deps = [ "//base" ]
+
+  lib_dirs = ["../samsung_cloud/"]
+  libs = [ "samsungcloud" ]
+
+  ldflags = [ "-Wl,-rpath=\$ORIGIN/../lib" ]
+
+  configs += [
+   "//tizen_src/build:ecore",
+   "//tizen_src/build:libecore",
+   "//tizen_src/build:ecore-evas",
+   "//tizen_src/build:libecore-evas",
+   "//tizen_src/build:elementary",
+   "//tizen_src/build:libelementary",
+   "//tizen_src/build:capi-window-tv",
+   "//tizen_src/build:libcapi-window-tv",
+   "//tizen_src/build:autoinput",
+       "//tizen_src/build:capi-cloud-tab",
+    "//tizen_src/build:libcapi-cloud-tab",
+    "//tizen_src/build:capi-media-image-util",
+    "//tizen_src/build:libcapi-media-image-util",
+  ]
+}
+
diff --git a/components/samsung/data_sync_service/data_sync_service_impl.cc b/components/samsung/data_sync_service/data_sync_service_impl.cc
new file mode 100644 (file)
index 0000000..765a773
--- /dev/null
@@ -0,0 +1,455 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/samsung/data_sync_service/data_sync_service_impl.h"
+
+#include "base/functional/bind.h"
+#include "base/logging.h"
+#include "base/task/thread_pool.h"
+
+namespace samsung_browser_service {
+constexpr float retrySyncTimer = 1.0f;
+constexpr int maxSyncRetryCount =
+    10;  // Max retries decided internally by browser.
+constexpr char jsonIconPath[] = "iconPath_40";
+
+#ifdef ENABLE_WATCHLATER
+samsung_cloud_adapter_e datasyncAdapterNames[datasyncAdapterCnt] = {
+    SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK, SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB,
+    SAMSUNG_CLOUD_ADAPTER_WATCH_LATER};
+#else
+samsung_cloud_adapter_e datasyncAdapterNames[datasyncAdapterCnt] = {
+    SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK, SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB};
+#endif
+
+DataSyncServiceImpl::DataSyncServiceImpl()
+    : m_initialized(false),
+      m_samsungCloudHandle(nullptr),
+      m_cloudInitialised(false),
+      m_isConnectionRequested(false),
+      m_syncEnable(false),
+      m_timerCnt(3) {
+  LOG(INFO) << "Constructor Start";
+
+  for (int i = 0; i < datasyncAdapterCnt; i++) {
+    m_isSyncing[i] = false;
+    m_syncRetryCount[i] = maxSyncRetryCount;
+    m_syncTimerHandler[i] = NULL;
+  }
+}
+
+DataSyncServiceImpl::~DataSyncServiceImpl() {
+  LOG(INFO) << "Clearing the account list vector";
+  m_linkedAccounts.clear();
+  m_linkedAccountsGUID.clear();
+}
+
+bool DataSyncServiceImpl::Init() {
+  LOG(INFO) << "DataSyncServiceImpl::Init()";
+  m_initialized = true;
+  return true;
+}
+
+void DataSyncServiceImpl::connectToCloud() {
+  LOG(INFO) << "DataSyncServiceImpl::connectToCloud() Start";
+  m_isConnectionRequested = true;
+  int err_code = SAMSUNG_CLOUD_ERROR_NONE;
+  err_code = samsung_cloud_connect(samsung_cloud_connection_status_changed_cb,
+                                   this, &m_samsungCloudHandle);
+
+  if (err_code != SAMSUNG_CLOUD_ERROR_NONE || !m_samsungCloudHandle) {
+    LOG(INFO) << "err_code [" << err_code << "]";
+    m_isConnectionRequested = false;
+  }
+
+  LOG(INFO) << "DataSyncServiceImpl::connectToCloud() done";
+}
+
+void DataSyncServiceImpl::disconnectToCloud() {
+  LOG(INFO) << "disconnectFromCloud Start";
+  if (m_samsungCloudHandle) {
+    LOG(INFO) << "Cloud Disconnection";
+    int err_code = samsung_cloud_disconnect(m_samsungCloudHandle);
+    if (err_code != SAMSUNG_CLOUD_ERROR_NONE) {
+      LOG(WARNING) << "Error disconnecting from cloud";
+    }
+    m_samsungCloudHandle = nullptr;
+  }
+
+  // reset all flags
+  m_cloudInitialised = false;
+  m_isConnectionRequested = false;
+  m_syncEnable = false;
+  m_timerCnt = 3;
+  for (int i = 0; i < datasyncAdapterCnt; i++) {
+    if (m_syncTimerHandler[i]) {
+      ecore_timer_del(m_syncTimerHandler[i]);
+      m_syncTimerHandler[i] = NULL;
+    }
+    m_isSyncing[i] = false;
+  }
+}
+
+void DataSyncServiceImpl::samsung_cloud_connection_status_changed_cb(
+    samsung_cloud_error_e result,
+    samsung_cloud_connection_status_e status,
+    void* user_data) {
+  DataSyncServiceImpl* self = reinterpret_cast<DataSyncServiceImpl*>(user_data);
+  LOG(INFO) << "status is " << status << " result is " << result;
+  self->m_isConnectionRequested = false;
+
+  switch (status) {
+    case SAMSUNG_CLOUD_CONNECTION_STATUS_CONNECTED:
+      LOG(INFO) << "SAMSUNG_CLOUD_CONNECTION_STATUS_CONNECTED";
+      self->m_cloudInitialised = true;
+      {
+        if (self->m_syncEnable) {
+          LOG(INFO) << "lazy sync - Bookmark and Tab are now enabled";
+        }
+        self->enableAdaptersAutoSync(true);
+      }
+      break;
+
+    case SAMSUNG_CLOUD_CONNECTION_STATUS_DISCONNECTED:
+      LOG(INFO) << "SAMSUNG_CLOUD_CONNECTION_STATUS_DISCONNECTED";
+      if (self->m_samsungCloudHandle) {
+        LOG(INFO) << "Cloud Disconnection";
+        samsung_cloud_disconnect(self->m_samsungCloudHandle);
+        self->m_samsungCloudHandle = nullptr;
+      }
+      if (self->m_timerCnt) {
+        self->m_timerCnt--;
+        self->connectToCloud();
+      }
+      break;
+
+    case SAMSUNG_CLOUD_CONNECTION_STATUS_REJECTED:
+      LOG(INFO) << "SAMSUNG_CLOUD_CONNECTION_STATUS_REJECTED";
+      // Developer need to check the priviledges applied in the browser side
+      // w.r.t usage of priviledges needed to samsung_cloud_connect
+      break;
+  }
+}
+
+void DataSyncServiceImpl::samsung_cloud_result_cb(int result, void* user_data) {
+  LOG(INFO) << "sync cancelled result: " << result;
+}
+
+void DataSyncServiceImpl::changeAdaptersState(
+    samsung_browser_main::SynchronizationItem adapter,
+    bool enable) {
+  LOG(INFO) << "changeAdaptersState Start";
+
+  // Check cloud connection
+  if (!m_cloudInitialised) {
+    LOG(WARNING) << "NOT connected with cloud";
+    return;
+  }
+
+  // Check adapter is supported
+  if (adapter >=
+      samsung_browser_main::SynchronizationItem::BookMarkTabAndWatchLater) {
+    LOG(WARNING) << "Unsupported adapter for this function...";
+    return;
+  }
+
+  // Check for the enabled adapters
+  int err_code = SAMSUNG_CLOUD_ERROR_NONE;
+  bool isEnabled = false;
+  err_code = samsung_cloud_get_adapter_enable(
+      m_samsungCloudHandle, datasyncAdapterNames[adapter], &isEnabled);
+
+  if (err_code != SAMSUNG_CLOUD_ERROR_NONE) {
+    LOG(WARNING) << "samsung_cloud_get_adapter_enable: adapter: " << adapter
+                 << "error code: " << err_code;
+    return;
+  }
+
+  LOG(INFO) << "adapter: " << adapter << " status: " << isEnabled;
+  LOG(INFO) << "enable: " << enable;
+  if (enable) {
+    if (isEnabled != enable) {
+      LOG(WARNING) << "Enable adapters";
+      err_code = samsung_cloud_set_adapter_enable(
+          m_samsungCloudHandle, datasyncAdapterNames[adapter], enable);
+      if (err_code != SAMSUNG_CLOUD_ERROR_NONE) {
+        LOG(WARNING) << "samsung_cloud_set_adapter_enable adapter: " << adapter
+                     << " returned error code: " << err_code;
+        return;
+      }
+    }
+    m_syncRetryCount[adapter] = maxSyncRetryCount;
+    syncAdapter(adapter);
+  } else {
+    if (isEnabled == enable) {
+      LOG(INFO) << "Adapters already disabled";
+      return;
+    }
+
+    LOG(INFO) << "Cancel sync and disable adapters";
+
+    switch (adapter) {
+      case samsung_browser_main::SynchronizationItem::Bookmarks:
+        if (m_syncTimerHandler[syncBookMark]) {
+          ecore_timer_del(m_syncTimerHandler[syncBookMark]);
+          m_syncTimerHandler[syncBookMark] = NULL;
+        }
+        m_isSyncing[adapter] = false;
+        break;
+      case samsung_browser_main::SynchronizationItem::Tabs:
+        if (m_syncTimerHandler[syncTab]) {
+          ecore_timer_del(m_syncTimerHandler[syncTab]);
+          m_syncTimerHandler[syncTab] = NULL;
+        }
+        m_isSyncing[adapter] = false;
+        break;
+
+#ifdef ENABLE_WATCHLATER
+      case samsung_browser_main::SynchronizationItem::WatchLater:
+        if (m_syncTimerHandler[syncWatchLater]) {
+          ecore_timer_del(m_syncTimerHandler[syncWatchLater]);
+          m_syncTimerHandler[syncTab] = NULL;
+        }
+        m_isSyncing[adapter] = false;
+        break;
+#endif
+      default:
+        LOG(WARNING) << "Should not reach here!!";
+        break;
+    }
+
+    err_code = samsung_cloud_cancel_sync(m_samsungCloudHandle,
+                                         datasyncAdapterNames[adapter],
+                                         samsung_cloud_result_cb, this);
+    if (err_code != SAMSUNG_CLOUD_ERROR_NONE) {
+      LOG(WARNING) << "samsung_cloud_cancel_sync [index]: " << adapter
+                   << " returned error code: " << err_code;
+      return;
+    }
+
+    err_code = samsung_cloud_set_adapter_enable(
+        m_samsungCloudHandle, datasyncAdapterNames[adapter], enable);
+    if (err_code != SAMSUNG_CLOUD_ERROR_NONE) {
+      LOG(WARNING) << "samsung_cloud_set_adapter_enable adapter: " << adapter
+                   << " returned error code: " << err_code;
+      return;
+    }
+  }
+}
+
+void DataSyncServiceImpl::syncAdapter(
+    samsung_browser_main::SynchronizationItem adapter) {
+  LOG(INFO) << "syncAdapter Start";
+  if (adapter >=
+      samsung_browser_main::SynchronizationItem::BookMarkTabAndWatchLater) {
+    LOG(INFO) << "Unsupported adapter for this function...";
+    return;
+  }
+  LOG(INFO) << "start sync adapter: " << adapter << " retry Count: "
+            << (maxSyncRetryCount - m_syncRetryCount[adapter] + 1);
+
+  if (!m_cloudInitialised) {
+    LOG(WARNING) << "NOT connected with cloud";
+    return;
+  }
+
+  if (!m_syncRetryCount[adapter]) {
+    LOG(WARNING) << "Exceeded Retry Count";
+    return;
+  }
+  int err_code = SAMSUNG_CLOUD_ERROR_NONE;
+
+  std::string str = "";
+
+  const char* sa = str.c_str();
+  LOG(INFO) << "sa is[%s]" << sa;
+
+  if (m_isSyncing[adapter]) {
+    LOG(ERROR) << "adapter " << adapter << " already syncing";
+    return;
+  }
+
+  switch (adapter) {
+    case samsung_browser_main::SynchronizationItem::Bookmarks:
+      if (m_syncTimerHandler[syncBookMark] == NULL) {
+        m_isSyncing[adapter] = true;
+        m_syncRetryCount[adapter]--;
+        err_code = samsung_cloud_start_sync(
+            m_samsungCloudHandle, datasyncAdapterNames[adapter], sa,
+            samsung_cloud_result_cbBookmark, this);
+      }
+      break;
+
+    case samsung_browser_main::SynchronizationItem::Tabs:
+      if (m_syncTimerHandler[syncTab] == NULL) {
+        m_isSyncing[adapter] = true;
+        m_syncRetryCount[adapter]--;
+        err_code = samsung_cloud_start_sync(m_samsungCloudHandle,
+                                            datasyncAdapterNames[adapter], sa,
+                                            samsung_cloud_result_cbTab, this);
+      }
+      break;
+
+#ifdef ENABLE_WATCHLATER
+    case samsung_browser_main::SynchronizationItem::WatchLater:
+      if (m_syncTimerHandler[syncWatchLater] == NULL) {
+        m_isSyncing[adapter] = true;
+        m_syncRetryCount[adapter]--;
+        err_code = samsung_cloud_start_sync(
+            m_samsungCloudHandle, datasyncAdapterNames[adapter], sa,
+            samsung_cloud_result_cbWatchLater, this);
+      }
+      break;
+#endif
+
+    default:
+      LOG(WARNING) << "Unknown adapter!!";
+      break;
+  }
+
+  if (err_code != SAMSUNG_CLOUD_ERROR_NONE) {
+    m_isSyncing[adapter] = false;
+    LOG(WARNING) << "ERROR samsung_cloud_start_sync adapter " << adapter
+                 << " error code = " << err_code;
+  }
+}
+
+// enable bookmark and tab sync
+void DataSyncServiceImpl::enableAdaptersAutoSync(
+    bool enable,
+    samsung_browser_main::SynchronizationItem item) {
+  LOG(INFO) << "enable = " << enable;
+
+  m_syncEnable = enable;
+  if (!m_cloudInitialised) {
+    LOG(WARNING) << "NOT connected with cloud, save enable " << enable
+                 << " for later";
+    if (!m_isConnectionRequested) {
+      if (!enable) {
+        LOG(INFO)
+            << "Cloud not initialized and sync disabled. Hence returning.";
+        return;
+      }
+      connectToCloud();
+    }
+    return;
+  }
+
+  if (!m_samsungCloudHandle) {
+    LOG(WARNING) << "Cloud handle is null";
+    return;
+  }
+
+  switch (item) {
+    case samsung_browser_main::SynchronizationItem::Bookmarks:
+      LOG(INFO) << "Changing Adapter State for Bookmarks";
+      changeAdaptersState(samsung_browser_main::SynchronizationItem::Bookmarks,
+                          enable);
+      break;
+
+    case samsung_browser_main::SynchronizationItem::Tabs:
+      LOG(INFO) << "Changing Adapter State for Tabs";
+      changeAdaptersState(samsung_browser_main::SynchronizationItem::Tabs,
+                          enable);
+      break;
+
+#ifdef ENABLE_WATCHLATER
+    case samsung_browser_main::SynchronizationItem::WatchLater:
+      LOG(INFO) << "Changing Adapter State for WatchLater";
+      changeAdaptersState(samsung_browser_main::SynchronizationItem::WatchLater,
+                          enable);
+      break;
+#endif
+
+    default:
+      LOG(INFO) << "Changing Adapter State for Default";
+      changeAdaptersState(samsung_browser_main::SynchronizationItem::Bookmarks,
+                          enable);
+      changeAdaptersState(samsung_browser_main::SynchronizationItem::Tabs,
+                          enable);
+#ifdef ENABLE_WATCHLATER
+      changeAdaptersState(samsung_browser_main::SynchronizationItem::WatchLater,
+                          enable);
+#endif
+      break;
+  }
+}
+
+void DataSyncServiceImpl::samsung_cloud_result_cbTab(int result,
+                                                     void* user_data) {
+  LOG(INFO) << "samsung_cloud_result_cbTab start";
+  LOG(INFO) << "result: " << result;
+
+  DataSyncServiceImpl* self = reinterpret_cast<DataSyncServiceImpl*>(user_data);
+
+  self->m_isSyncing[samsung_browser_main::SynchronizationItem::Tabs] = false;
+
+  if ((SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE == result) ||
+      (SAMSUNG_CLOUD_ERROR_UNKNOWN == result)) {
+    if (self->m_syncTimerHandler[syncTab] == NULL) {
+      self->m_syncTimerHandler[syncTab] =
+          ecore_timer_add(retrySyncTimer, syncRetrySyncTabTimerCallback, self);
+    }
+  } else if (SAMSUNG_CLOUD_ERROR_NONE == result) {
+    if (self->m_syncTimerHandler[syncTab]) {
+      ecore_timer_del(self->m_syncTimerHandler[syncTab]);
+      self->m_syncTimerHandler[syncTab] = NULL;
+    }
+    LOG(INFO) << "Tab Sync Done";
+  }
+}
+
+void DataSyncServiceImpl::samsung_cloud_result_cbBookmark(int result,
+                                                          void* user_data) {
+  LOG(INFO) << "samsung_cloud_result_cbBookmark start";
+  LOG(INFO) << "result: " << result;
+
+  DataSyncServiceImpl* self = reinterpret_cast<DataSyncServiceImpl*>(user_data);
+
+  self->m_isSyncing[samsung_browser_main::SynchronizationItem::Bookmarks] =
+      false;
+
+  if ((SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE == result) ||
+      (SAMSUNG_CLOUD_ERROR_UNKNOWN == result)) {
+    if (self->m_syncTimerHandler[syncBookMark] == NULL) {
+      self->m_syncTimerHandler[syncBookMark] =
+          ecore_timer_add(retrySyncTimer, syncRetryBookMarkTimerCallback, self);
+    }
+  } else if (SAMSUNG_CLOUD_ERROR_NONE == result) {
+    if (self->m_syncTimerHandler[syncBookMark]) {
+      ecore_timer_del(self->m_syncTimerHandler[syncBookMark]);
+      self->m_syncTimerHandler[syncBookMark] = NULL;
+    }
+    LOG(INFO) << "Bookmark sync done";
+  }
+}
+
+Eina_Bool DataSyncServiceImpl::syncRetryBookMarkTimerCallback(void* data) {
+  LOG(INFO) << "syncRetryBookMarkTimerCallback start";
+  DataSyncServiceImpl* self = reinterpret_cast<DataSyncServiceImpl*>(data);
+  if (!self) {
+    LOG(WARNING) << "data is NULL";
+    return ECORE_CALLBACK_CANCEL;
+  }
+
+  self->m_syncTimerHandler[syncBookMark] = NULL;
+  LOG(INFO) << "Retrying sync for bookmarks..";
+  self->syncAdapter(samsung_browser_main::SynchronizationItem::Bookmarks);
+  return ECORE_CALLBACK_CANCEL;
+}
+
+Eina_Bool DataSyncServiceImpl::syncRetrySyncTabTimerCallback(void* data) {
+  LOG(INFO) << "syncRetrySyncTabTimerCallback start";
+  DataSyncServiceImpl* self = reinterpret_cast<DataSyncServiceImpl*>(data);
+  if (!self) {
+    LOG(WARNING) << "data is Null";
+    return ECORE_CALLBACK_CANCEL;
+  }
+  self->m_syncTimerHandler[syncTab] = NULL;
+  LOG(INFO) << "Retrying sync for open tabs..";
+  self->syncAdapter(samsung_browser_main::SynchronizationItem::Tabs);
+  return ECORE_CALLBACK_CANCEL;
+}
+
+}  // namespace samsung_browser_service
\ No newline at end of file
diff --git a/components/samsung/data_sync_service/data_sync_service_impl.h b/components/samsung/data_sync_service/data_sync_service_impl.h
new file mode 100644 (file)
index 0000000..6b6992f
--- /dev/null
@@ -0,0 +1,83 @@
+#ifndef CHROME_BROWSER_UI_SAMSUNG_DATA_SYNC_SERVICE_H_
+#define CHROME_BROWSER_UI_SAMSUNG_DATA_SYNC_SERVICE_H_
+
+#include <Ecore.h>
+#include <Ecore_Evas.h>
+#include <Elementary.h>
+#include <Evas.h>
+#include <string>
+#include "base/memory/raw_ptr.h"
+#include "base/observer_list.h"
+#include "base/task/sequenced_task_runner.h"
+#include "base/task/thread_pool.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
+#include "components/samsung/public/samsung_browser_enums.h"
+#include "components/samsung/samsung_cloud/samsung_cloud.h"
+#include "components/samsung/samsung_cloud/samsung_cloud_error.h"
+#include "components/samsung/samsung_cloud/samsung_cloud_service.h"
+
+namespace samsung_browser_service {
+
+enum {
+  syncBookMark = 0,
+  syncTab,
+#ifdef ENABLE_WATCHLATER
+  syncWatchLater,
+#endif
+  syncAdapterSize,
+};
+
+#ifdef ENABLE_WATCHLATER
+constexpr int datasyncAdapterCnt = 3;
+#else
+constexpr int datasyncAdapterCnt = 2;
+#endif
+
+class DataSyncServiceImpl {
+ public:
+  DataSyncServiceImpl();
+  virtual ~DataSyncServiceImpl();
+  bool Init();
+  void initOpenedTabModel();
+  void connectToCloud();
+  void disconnectToCloud();
+  void enableAdaptersAutoSync(
+      bool,
+      samsung_browser_main::SynchronizationItem item =
+          samsung_browser_main::SynchronizationItem::BookMarkTabAndWatchLater);
+  void changeAdaptersState(samsung_browser_main::SynchronizationItem, bool);
+  void syncAdapter(samsung_browser_main::SynchronizationItem);
+
+ private:
+  static void samsung_cloud_connection_status_changed_cb(
+      samsung_cloud_error_e,
+      samsung_cloud_connection_status_e,
+      void* user_data);
+  static void samsung_cloud_result_cb(int result, void* user_data);
+  static void samsung_cloud_result_cbTab(int result, void* user_data);
+  static void samsung_cloud_result_cbBookmark(int result, void* user_data);
+
+  static Eina_Bool syncRetryBookMarkTimerCallback(void*);
+  static Eina_Bool syncRetrySyncTabTimerCallback(void*);
+  // Account
+  bool m_initialized;
+  // BrowserFWCore::LoginInfo m_loginInfo;
+  // Cloud
+  samsung_cloud_h m_samsungCloudHandle;
+  bool m_cloudInitialised;
+  bool m_isConnectionRequested;
+  bool m_syncEnable;
+  bool m_opened_tab_initialized;
+  int m_timerCnt;
+  bool m_isSyncing[datasyncAdapterCnt];  // should be same as datasyncAdapterCnt
+  int m_syncRetryCount[datasyncAdapterCnt];  // for number of times sync
+                                             // attempted max 10
+  Ecore_Timer* m_syncTimerHandler[syncAdapterSize];
+  bool m_svcUpdateInProgress;
+  // AccountList
+  std::vector<std::string> m_linkedAccounts;
+  std::vector<std::string> m_linkedAccountsGUID;
+};
+}  // namespace samsung_browser_service
+#endif
\ No newline at end of file
diff --git a/components/samsung/opened_tabs/BUILD.gn b/components/samsung/opened_tabs/BUILD.gn
new file mode 100644 (file)
index 0000000..1b86d5a
--- /dev/null
@@ -0,0 +1,17 @@
+source_set("opened_tabs") {
+  sources = [
+    "opened_tab_id.h",
+    "opened_tab_item.cc",
+    "opened_tab_item.h",
+    "tab_id_store.h",
+    "opened_tab_model.cc",
+    "opened_tab_model.h",
+  ]
+
+  public_deps = [ "//base" ]
+
+  configs += [
+    "//tizen_src/build:capi-cloud-tab",
+    "//tizen_src/build:libcapi-cloud-tab",
+  ]
+}
diff --git a/components/samsung/opened_tabs/account_model.h b/components/samsung/opened_tabs/account_model.h
new file mode 100644 (file)
index 0000000..b301fd5
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef COMPONENTS_SAMSUNG_OPENED_TABS_ACCOUNT_MODEL_H_
+#define COMPONENTS_SAMSUNG_OPENED_TABS_ACCOUNT_MODEL_H_
+
+#include "iaccount_model.h"
+
+namespace samsung_browser_fw_core {
+
+class AccountModel : public IAccountModel {
+ public:
+  AccountModel() = default;
+
+  virtual ~AccountModel() {}
+#ifdef LOCAL_AUTOFILL
+  const std::string& getUserId() const override { return m_userId; }
+  virtual void setUserId(const std::string& userId) override {
+    m_userId = userId;
+  }
+#endif
+  virtual const std::string& getAccountName() const override {
+    return m_userName;
+  }
+  virtual void setAccountName(const std::string& userName) override {
+    m_userName = userName;
+  }
+
+ protected:
+  std::string m_userName;
+#ifdef LOCAL_AUTOFILL
+  std::string m_userId;
+#endif
+};
+
+}  // namespace samsung_browser_fw_core
+
+#endif  // COMPONENTS_SAMSUNG_OPENED_TABS_ACCOUNT_MODEL_H_
diff --git a/components/samsung/opened_tabs/iaccount_model.h b/components/samsung/opened_tabs/iaccount_model.h
new file mode 100644 (file)
index 0000000..f8a8456
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef COMPONENTS_SAMSUNG_OPENED_TABS_IACCOUNT_MODEL_H_
+#define COMPONENTS_SAMSUNG_OPENED_TABS_IACCOUNT_MODEL_H_
+
+#include <string>
+
+namespace samsung_browser_fw_core {
+
+class IAccountModel {
+ public:
+  virtual ~IAccountModel() {}
+#ifdef LOCAL_AUTOFILL
+  virtual const std::string& getUserId() const = 0;
+  virtual void setUserId(const std::string& userId) = 0;
+#endif
+  virtual const std::string& getAccountName() const = 0;
+  virtual void setAccountName(const std::string&) = 0;
+};
+
+}  // namespace samsung_browser_fw_core
+
+#endif  // COMPONENTS_SAMSUNG_OPENED_TABS_IACCOUNT_MODEL_H_
diff --git a/components/samsung/opened_tabs/opened_tab_id.h b/components/samsung/opened_tabs/opened_tab_id.h
new file mode 100644 (file)
index 0000000..48b4745
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_ID_H_
+#define COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_ID_H_
+
+#include "components/samsung/public/samsung_abstract_id.h"
+
+namespace samsung_browser_fw_core {
+
+class OpenedTabID : public SamsungAbstractID {
+ public:
+  OpenedTabID() : SamsungAbstractID() {}
+  OpenedTabID(const std::string& str) : SamsungAbstractID(str) {}
+
+  static OpenedTabID NONE;
+};
+
+}  // namespace samsung_browser_fw_core
+#endif  // COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_ID_H_
diff --git a/components/samsung/opened_tabs/opened_tab_item.cc b/components/samsung/opened_tabs/opened_tab_item.cc
new file mode 100644 (file)
index 0000000..bb5fc46
--- /dev/null
@@ -0,0 +1,52 @@
+#include "opened_tab_item.h"
+#include <chrono>
+#include <ctime>
+#include "tab_id_store.h"
+
+namespace samsung_browser_fw_core {
+
+OpenedTabItem OpenedTabItem::INVALID = OpenedTabItem();
+
+OpenedTabItem::OpenedTabItem()
+    : m_id(),
+      m_creationTime(std::chrono::system_clock::now()),
+      m_accessTime(std::chrono::system_clock::now()) {}
+
+OpenedTabItem::~OpenedTabItem() {
+  //
+}
+
+OpenedTabItem::OpenedTabItem(const std::string& url,
+                             const std::string& title,
+                             const std::string& device_name,
+                             const std::string& device_id)
+    : m_id(),
+      m_url(url),
+      m_title(title),
+      m_creationTime(std::chrono::system_clock::now()),
+      m_accessTime(std::chrono::system_clock::now()),
+      m_deviceName(device_name),
+      m_deviceId(device_id) {}
+
+OpenedTabItem::OpenedTabItem(const std::string& id,
+                             const std::string& url,
+                             const std::string& title,
+                             const std::string& device_name,
+                             const std::string& device_id)
+    : m_id(id),
+      m_url(url),
+      m_title(title),
+      m_creationTime(std::chrono::system_clock::now()),
+      m_accessTime(std::chrono::system_clock::now()),
+      m_deviceName(device_name),
+      m_deviceId(device_id) {}
+
+bool OpenedTabItem::operator==(const OpenedTabItem& other) const {
+  return m_id == other.m_id;
+}
+
+bool OpenedTabItem::operator!=(const OpenedTabItem& other) const {
+  return m_id != other.m_id;
+}
+
+}  // namespace samsung_browser_fw_core
diff --git a/components/samsung/opened_tabs/opened_tab_item.h b/components/samsung/opened_tabs/opened_tab_item.h
new file mode 100644 (file)
index 0000000..eb4fe82
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_ITEM_H
+#define COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_ITEM_H
+
+#include "components/samsung/public/samsung_enums.h"
+#include "opened_tab_id.h"
+
+#include <chrono>
+
+namespace samsung_browser_fw_core {
+
+class OpenedTabItem {
+ public:
+  OpenedTabItem();
+  OpenedTabItem(const std::string& id,
+                const std::string& url,
+                const std::string& title,
+                const std::string& device,
+                const std::string& device_id);
+  OpenedTabItem(const std::string& url,
+                const std::string& title,
+                const std::string& device,
+                const std::string& device_id);
+  OpenedTabItem(const OpenedTabItem&) = default;
+
+  virtual ~OpenedTabItem();
+  virtual OpenedTabItem& operator=(const OpenedTabItem&) = default;
+  virtual bool operator==(const OpenedTabItem& other) const;
+  virtual bool operator!=(const OpenedTabItem& other) const;
+
+  virtual void setID(OpenedTabID id) { m_id = id; }
+  virtual OpenedTabID getID() const { return m_id; }
+
+  virtual void setURL(std::string& url) { m_url = url; }
+  virtual std::string getURL() const { return m_url; }
+
+  virtual void setTitle(const std::string& title) { m_title = title; }
+  virtual std::string getTitle() const { return m_title; }
+
+  virtual void setCreationTime(
+      std::chrono::time_point<std::chrono::system_clock> t) {
+    m_creationTime = t;
+  }
+  virtual std::chrono::time_point<std::chrono::system_clock> getCreationTime()
+      const {
+    return m_creationTime;
+  }
+
+  virtual void setAccessTime(
+      std::chrono::time_point<std::chrono::system_clock> t) {
+    m_accessTime = t;
+  }
+  virtual std::chrono::time_point<std::chrono::system_clock> getAccessTime()
+      const {
+    return m_accessTime;
+  }
+
+  virtual void setDeviceName(const std::string& dev) { m_deviceName = dev; }
+  virtual std::string getDeviceName() const { return m_deviceName; }
+  virtual void setDeviceId(const std::string& dev_id) { m_deviceId = dev_id; }
+  virtual std::string getDeviceId() const { return m_deviceId; }
+
+  static OpenedTabItem INVALID;
+
+ private:
+  OpenedTabID m_id;
+  std::string m_url;
+  std::string m_title;
+  std::chrono::time_point<std::chrono::system_clock> m_creationTime;
+  std::chrono::time_point<std::chrono::system_clock> m_accessTime;
+  std::string m_deviceName;
+  std::string m_deviceId;
+};
+
+}  // namespace samsung_browser_fw_core
+#endif  // OpenedTabItem_h
+//
diff --git a/components/samsung/opened_tabs/opened_tab_model.cc b/components/samsung/opened_tabs/opened_tab_model.cc
new file mode 100644 (file)
index 0000000..46372cc
--- /dev/null
@@ -0,0 +1,606 @@
+#include "opened_tab_model.h"
+
+#include "base/logging.h"
+#include "components/samsung/public/samsung_utility.h"
+
+#include <Ecore.h>
+#include <string.h>
+#include "cloud_tab.h"
+
+namespace samsung_browser_storage {
+bp_tab_info_fmt convert(const samsung_browser_fw_core::OpenedTabItem& item) {
+  bp_tab_info_fmt info;
+  memset(&info, 0x00, sizeof(bp_tab_info_fmt));
+  info.is_activated = 1;
+  info.url = strdupa(item.getURL().c_str());
+  info.title = strdupa(item.getTitle().c_str());
+  info.device_name = strdupa(item.getDeviceName().c_str());
+  info.device_id = strdupa(item.getDeviceId().c_str());
+  return info;
+}
+
+std::string BPOpenedTabModel::sourceName = "BrowserProviderTabs";
+
+bool BPOpenedTabModel::m_initialized = false;
+BPOpenedTabModel::BPOpenedTabModel() : m_OpenedTabAdaptorInitialized(false) {}
+
+BPOpenedTabModel::~BPOpenedTabModel() {
+  deinit();
+}
+
+bool BPOpenedTabModel::init() {
+  m_initialized = true;
+  return true;
+}
+
+void BPOpenedTabModel::initializeOpenedTabAdaptor() {
+  if (m_OpenedTabAdaptorInitialized) {
+    LOG(INFO) << "Already initialized";
+    return;
+  }
+  if (tab_adaptor_initialize() != 0) {
+    LOG(INFO) << "Failed to initialize openedtab adaptor";
+    return;
+  }
+
+  if (tab_adaptor_set_data_changed_cb(&BPOpenedTabModel::dataChangedCallback,
+                                      this) != 0) {
+    LOG(INFO) << "Failed to register openedtab adaptor data changed cb";
+    if (tab_adaptor_deinitialize() != 0) {
+      LOG(INFO) << "failed to deinitialize openedtab adaptor";
+    }
+    return;
+  }
+  m_OpenedTabAdaptorInitialized = true;
+}
+
+void BPOpenedTabModel::deinit() {
+  m_initialized = false;
+  if (m_OpenedTabAdaptorInitialized) {
+    if (tab_adaptor_unset_data_changed_cb(
+            &BPOpenedTabModel::dataChangedCallback) != 0) {
+      LOG(INFO) << "Failed to unregister openedtab adaptor data changed cb";
+    }
+
+    if (tab_adaptor_deinitialize() != 0) {
+      LOG(INFO) << "Failed to deinitialize openedtab adaptor";
+    }
+    m_OpenedTabAdaptorInitialized = false;
+  }
+}
+void BPOpenedTabModel::tabInfoFree(bp_tab_info_fmt* info) {
+  if (info != NULL) {
+    free(info->url);
+    free(info->title);
+    free(info->account_name);
+    free(info->account_type);
+    free(info->device_name);
+    free(info->device_id);
+    free(info->favicon);
+    free(info->thumbnail);
+    free(info->usage);
+    free(info->sync);
+    memset(info, 0x00, sizeof(bp_tab_info_fmt));
+  }
+}
+void BPOpenedTabModel::dataChangedCallback(void* data) {
+  // if (BrowserMain::BrowserCore::isTerminated())
+  // {
+  //   BROWSER_LOGD("");
+  //   return;
+  // }
+
+  BPOpenedTabModel* self = static_cast<BPOpenedTabModel*>(data);
+
+  self->dataChanged();
+}
+
+void BPOpenedTabModel::dataChanged() {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  // TODO: find changed items and signal for each change
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  // TODO: convert to FireWebUIListener() call
+  // sendSignal(new BPOpenedTabSigData(this,
+  // BPOpenedTabSigData::SigType::OpenedTabChanged,
+  // samsung_browser_fw_core::OpenedTabItem::INVALID));
+}
+
+bool BPOpenedTabModel::add(samsung_browser_fw_core::OpenedTabItem& item) {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  int id = m_idStore.find(item.getID());
+  bool isNewItem = (id == -1);
+  tab_info_h handle;
+  int errorcode = 0;
+  errorcode = tab_adaptor_info_create(&handle);
+  if (errorcode != 0) {
+    LOG(INFO) << "tab_adaptor_info_create returned error. Error[" << errorcode
+              << "]";
+    return false;
+  }
+
+  if (tab_adaptor_info_set_url(handle, item.getURL().c_str()) != 0) {
+    LOG(INFO) << "Cannot set url";
+    tab_adaptor_info_destroy(handle);
+    return false;
+  }
+
+  if (tab_adaptor_info_set_title(handle, item.getTitle().c_str()) != 0) {
+    LOG(INFO) << "Cannot set title";
+    tab_adaptor_info_destroy(handle);
+    return false;
+  }
+
+  if (tab_adaptor_info_set_device_id(handle, item.getDeviceId().c_str()) != 0) {
+    LOG(INFO) << "Cannot set device id";
+    tab_adaptor_info_destroy(handle);
+    return false;
+  }
+
+  if (tab_adaptor_info_set_device_name(handle, item.getDeviceName().c_str()) !=
+      0) {
+    LOG(INFO) << "Cannot set device name";
+    tab_adaptor_info_destroy(handle);
+    return false;
+  }
+
+  if (getAccountName().size()) {
+    if (tab_adaptor_info_set_account_name(handle, getAccountName().c_str()) !=
+        0) {
+      LOG(INFO) << "Cannot set account name";
+      tab_adaptor_info_destroy(handle);
+      return false;
+    }
+  }
+
+  if (tab_adaptor_info_add_to_db(&id, handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_add_to_db returned error";
+    tab_adaptor_info_destroy(handle);
+    return false;
+  }
+
+  if (tab_adaptor_info_destroy(handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_destroy returned error";
+    return false;
+  }
+
+  LOG(INFO) << id;
+
+  if (tab_adaptor_publish_notification() != 0) {
+    LOG(INFO) << "Cannot publish notification";
+    return false;
+  }
+
+  if (isNewItem) {
+    m_idStore.add(item.getID(), id);
+  }
+
+  return true;
+}
+
+bool BPOpenedTabModel::remove(
+    const samsung_browser_fw_core::OpenedTabItem& item) {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  auto cloudId = m_idStore.find(item.getID());
+  if (cloudId == -1) {
+    LOG(INFO) << "Not known item";
+    return false;
+  }
+  LOG(INFO) << cloudId;
+  if (tab_adaptor_delete(cloudId) != 0) {
+    LOG(INFO) << "Cannot delete";
+    return false;
+  }
+
+  m_idStore.remove(item.getID());
+
+  if (tab_adaptor_publish_notification() != 0) {
+    LOG(INFO) << "Cannot publish notification";
+    return false;
+  }
+  return true;
+}
+
+bool BPOpenedTabModel::removeDevice(const std::string& device) {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  std::vector<samsung_browser_fw_core::OpenedTabItem> items = getOpenedTabs(
+      device, samsung_browser_storage::OpenedTabItemOrder::Url, 0, 0);
+  for (const auto& item : items) {
+    if (!remove(item)) {
+      return false;
+    }
+  }
+  return true;
+}
+
+bool BPOpenedTabModel::removeAll() {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  int* ids = nullptr;
+  int ids_count = -1;
+
+  if (tab_adaptor_get_full_id_list(&ids, &ids_count) != 0) {
+    LOG(INFO) << "ERROR in tab_adaptor_get_full_id_list";
+    if (ids) {
+      free(ids);
+    }
+    return false;
+  }
+  if (!ids) {
+    return false;
+  }
+  for (int i = 0; i < ids_count; ++i) {
+    if (tab_adaptor_delete(ids[i]) != 0) {
+      LOG(INFO) << "ERROR deleting tab id " << ids[i];
+    }
+    m_idStore.remove(ids[i]);
+  }
+  if (tab_adaptor_publish_notification() != 0) {
+    LOG(INFO) << "Cannot publish notification";
+    free(ids);
+    return false;
+  }
+
+  if (ids) {
+    free(ids);
+  }
+  return true;
+}
+
+samsung_browser_fw_core::OpenedTabItem BPOpenedTabModel::getOpenedTabItem(
+    int cloud_id) {
+  // if(BrowserMain::BrowserCore::isTerminated())
+  // {
+  //   BROWSER_LOGW("Browser is terminating!");
+  //   return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  // }
+  bp_tab_info_fmt info;
+  tab_info_h handle;
+  int errorcode = 0;
+  LOG(INFO) << "cloud_id: " << cloud_id;
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  memset(&info, 0x00, sizeof(bp_tab_info_fmt));
+  errorcode = tab_adaptor_info_create(&handle);
+  if (errorcode != 0) {
+    LOG(INFO) << "tab_Adaptor_info_create returned error. Error[" << errorcode
+              << "]";
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_from_db(cloud_id, handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_from_db returned error";
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+  auto tab_id = m_idStore.find(cloud_id);
+  if (tab_id == samsung_browser_fw_core::OpenedTabID::NONE) {
+    tab_id = samsung_browser_fw_core::OpenedTabID();
+    m_idStore.add(tab_id, cloud_id);
+  }
+  if (tab_adaptor_info_get_account_name(handle, &info.account_name) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_account_name returned error";
+    tabInfoFree(&info);
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  auto accountName = samsung_utility::stringFromCstr(info.account_name);
+  // if (accountName != getAccountName())
+  // {
+  //   tabInfoFree(&info);
+  //   tab_adaptor_info_destroy(handle);
+  //   return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  // }
+
+  if (tab_adaptor_info_get_url(handle, &info.url) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_url returned error";
+    tabInfoFree(&info);
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_title(handle, &info.title) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_title returned error";
+    tabInfoFree(&info);
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_device_id(handle, &info.device_id) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_device_id returned error";
+    tabInfoFree(&info);
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_device_name(handle, &info.device_name) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_device_name returned error";
+    tabInfoFree(&info);
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+  if (tab_adaptor_info_destroy(handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_destroy returned error";
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+  LOG(INFO) << tab_id.toString().c_str() << ", " << info.url << ", "
+            << info.title << ", " << info.account_name << ", "
+            << info.device_id;
+  samsung_browser_fw_core::OpenedTabItem item(
+      tab_id.toString(), samsung_utility::stringFromCstr(info.url),
+      samsung_utility::stringFromCstr(info.title),
+      samsung_utility::stringFromCstr(info.device_name),
+      samsung_utility::stringFromCstr(info.device_id));
+
+  tabInfoFree(&info);
+  return item;
+}
+
+std::vector<samsung_browser_fw_core::OpenedTabItem>
+BPOpenedTabModel::getOpenedTabs(
+    const std::string& device,
+    samsung_browser_storage::OpenedTabItemOrder order,
+    int limit,
+    int offset) {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  int* ids = nullptr;
+  int ids_count = -1;
+
+  if (tab_adaptor_get_id_list_by_keyword(
+          &ids, &ids_count, -1, 0, TAB_PROPERTY_DATE_CREATED, 0,
+          TAB_PROPERTY_DEVICE_ID, device.c_str(), 0) != 0) {
+    LOG(INFO) << "tab_adaptor_get_id_list_by_keyword returned error";
+    return std::vector<samsung_browser_fw_core::OpenedTabItem>();
+  }
+
+  if (ids_count <= 0 || !ids) {
+    // ids is empty and don't have to be free'd
+    return std::vector<samsung_browser_fw_core::OpenedTabItem>();
+  }
+
+  // Ensure that idStore will hold all id's, what is important in matching
+  for (int i = 0; i < ids_count; i++) {
+    auto tab_id = samsung_browser_fw_core::OpenedTabID();
+    m_idStore.add(tab_id, ids[i]);
+  }
+
+  // Fill items vector
+  LOG(INFO) << "Tabs in database : " << ids_count;
+  std::vector<samsung_browser_fw_core::OpenedTabItem> items;
+  // ids_count could be not equal than items.size if will be more than one user
+  // in database
+  items.reserve(ids_count);
+
+  for (int i = 0; i < ids_count; i++) {
+    auto item = getOpenedTabItem(ids[i]);
+    if (item != samsung_browser_fw_core::OpenedTabItem::INVALID) {
+      items.push_back(item);
+    }
+  }
+
+  // ids is validated previously, here we are shure that it have to be freed
+  free(ids);
+
+  return items;
+}
+
+samsung_browser_fw_core::OpenedTabItem BPOpenedTabModel::getOpenedTab(
+    const samsung_browser_fw_core::OpenedTabID& id) {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  auto cloudId = m_idStore.find(id);
+  if (cloudId == -1) {
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  bp_tab_info_fmt info;
+  memset(&info, 0x00, sizeof(bp_tab_info_fmt));
+  tab_info_h handle;
+  if (tab_adaptor_info_create(&handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_create returned error";
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_from_db(cloudId, handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_from_db returned error";
+    tab_adaptor_info_destroy(handle);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_account_name(handle, &info.account_name) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_account_name returned error";
+    tab_adaptor_info_destroy(handle);
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_url(handle, &info.url) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_url returned error";
+    tab_adaptor_info_destroy(handle);
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_title(handle, &info.title) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_title returned error";
+    tab_adaptor_info_destroy(handle);
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_device_name(handle, &info.device_name) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_device_name returned error";
+    tab_adaptor_info_destroy(handle);
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_get_device_id(handle, &info.device_id) != 0) {
+    LOG(INFO) << "tab_adaptor_info_get_device_id returned error";
+    tab_adaptor_info_destroy(handle);
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+
+  if (tab_adaptor_info_destroy(handle) != 0) {
+    LOG(INFO) << "tab_adaptor_info_destroy returned error";
+    tabInfoFree(&info);
+    return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  }
+  auto accountName = samsung_utility::stringFromCstr(info.account_name);
+  // if (accountName != getAccountName())
+  // {
+  //   tabInfoFree(&info);
+  //   return samsung_browser_fw_core::OpenedTabItem::INVALID;
+  // }
+
+  samsung_browser_fw_core::OpenedTabItem item(
+      id.toString(), samsung_utility::stringFromCstr(info.url),
+      samsung_utility::stringFromCstr(info.title),
+      samsung_utility::stringFromCstr(info.device_name),
+      samsung_utility::stringFromCstr(info.device_id));
+
+  tabInfoFree(&info);
+  return item;
+}
+
+int BPOpenedTabModel::count() {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  int* ids = nullptr;
+  int ids_count = -1;
+  if (tab_adaptor_get_full_id_list(&ids, &ids_count) != 0) {
+    LOG(INFO) << "Cannot get full ids";
+    return 0;
+  }
+  if (!ids) {
+    return 0;
+  }
+  LOG(INFO) << "ids_count=" << ids_count;
+  auto tempCount = ids_count;
+  for (int i = 0; i < ids_count; i++) {
+    tab_info_h handle = NULL;
+    int errorcode = 0;
+    char* accountName = nullptr;
+
+    errorcode = tab_adaptor_info_create(&handle);
+    if (errorcode != 0) {
+      LOG(INFO) << "tab_Adaptor_info_create returned error. Error[" << errorcode
+                << "]";
+    }
+    errorcode = tab_adaptor_info_get_from_db(ids[i], handle);
+    if (errorcode != 0) {
+      LOG(INFO) << "tab_adaptor_info_get_from_db returned error. Error["
+                << errorcode << "]";
+    }
+
+    errorcode = tab_adaptor_info_get_account_name(handle, &accountName);
+    if (errorcode != 0) {
+      LOG(INFO) << "tab_adaptor_info_get_account_name returned error. Error["
+                << errorcode << "]";
+    }
+    errorcode = tab_adaptor_info_destroy(handle);
+    if (errorcode != 0) {
+      LOG(INFO) << "tab_adaptor_info_destroy returned error. Error["
+                << errorcode << "]";
+    }
+    if (samsung_utility::stringFromCstr(accountName) != getAccountName()) {
+      --tempCount;
+    }
+    if (accountName) {
+      LOG(INFO) << "bp_tab_adaptor_get_account_name = [" << accountName << "]";
+      free(accountName);
+      accountName = nullptr;
+    }
+  }
+
+  if (ids) {
+    free(ids);
+  }
+
+  return tempCount;
+}
+
+std::vector<std::string> BPOpenedTabModel::getDeviceList() {
+  LOG(INFO) << "m_OpenedTabAdaptorInitialized ["
+            << m_OpenedTabAdaptorInitialized << "]";
+  if (!m_OpenedTabAdaptorInitialized) {
+    initializeOpenedTabAdaptor();
+  }
+  std::vector<std::string> devices;
+  int* ids = nullptr;
+  int ids_count = -1;
+  int device_counter = 0;
+  if (tab_adaptor_get_full_id_list(&ids, &ids_count) != 0) {
+    LOG(INFO) << "Cannot get full ids";
+    return devices;
+  }
+  if (!ids) {
+    return devices;
+  }
+  // Fill items vector
+  LOG(INFO) << "Tabs in database : " << ids_count;
+  std::vector<samsung_browser_fw_core::OpenedTabItem> items;
+  items.reserve(ids_count);
+
+  for (int i = 0; i < ids_count; i++) {
+    auto item = getOpenedTabItem(ids[i]);
+    if (item != samsung_browser_fw_core::OpenedTabItem::INVALID) {
+      items.push_back(item);
+    }
+  }
+  LOG(INFO) << "items size " << items.size();
+
+  if (items.size() != 0) {
+    devices.push_back(items[0].getDeviceId());
+    device_counter++;
+    for (std::vector<int>::size_type i = 1; i < items.size(); i++) {
+      devices.push_back(items[i].getDeviceId());
+      device_counter++;
+      LOG(INFO) << items[i].getDeviceId().c_str();
+      for (int j = device_counter - 1; j >= 1; j--) {
+        if (devices[j - 1] == items[i].getDeviceId()) {
+          devices.pop_back();
+          device_counter--;
+        }
+      }
+    }
+  }
+  LOG(INFO) << "devices size " << devices.size();
+  free(ids);
+  return devices;
+}
+
+}  // namespace samsung_browser_storage
diff --git a/components/samsung/opened_tabs/opened_tab_model.h b/components/samsung/opened_tabs/opened_tab_model.h
new file mode 100644 (file)
index 0000000..b39419f
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_MODEL_H_
+#define COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_MODEL_H_
+
+#include <vector>
+#include "cloud_tab.h"
+
+#include "account_model.h"
+#include "components/samsung/public/samsung_enums.h"
+#include "opened_tab_id.h"
+#include "opened_tab_item.h"
+#include "tab_id_store.h"
+
+namespace samsung_browser_storage {
+typedef struct {
+  int index;        /**< The index of the tab, otherwise ignore this variable by
+                       setting to negative */
+  int is_activated; /**< 1 means activated and 0 means deactivated, otherwise
+                       ignore this variable by setting to negative */
+  int is_incognito; /**< 1 means incognito and 0 - the opposite, ignore this
+                       variable by setting to negative */
+  int browser_instance; /**< 0 means default browser, otherwise multi instance
+                           browser, ignore this variable by setting to negative
+                         */
+  int dirty;            /**< deprecated */
+  int date_created;   /**< the creation time; ignore this variable by setting to
+                         zero */
+  int date_modified;  /**< the time of the last modification; ignore this
+                         variable by setting to zero */
+  int favicon_length; /**< the favicon length; ignore favicon by setting to zero
+                       */
+  int favicon_width;  /**< the favicon width */
+  int favicon_height; /**< the favicon height */
+  int thumbnail_length;     /**< ignore favicon by setting to zero */
+  int thumbnail_width;      /**< the thumbnail width */
+  int thumbnail_height;     /**< the tumbnail height */
+  char* url;                /**< the url */
+  char* title;              /**< the title */
+  char* account_name;       /**< the account name */
+  char* account_type;       /**< the account type */
+  char* device_name;        /**< the device name */
+  char* device_id;          /**< the device id */
+  char* usage;              /**< not support yet */
+  char* sync;               /**< extra property for sync */
+  unsigned char* favicon;   /**< row data of icon ( favorites icon ) */
+  unsigned char* thumbnail; /**< row data of snapshot */
+} bp_tab_info_fmt;
+
+enum OpenedTabItemOrder {
+  CreationTime = 1,
+  AccessTime = 2,
+  Url = 3,
+  Title = 4
+};
+
+class BPOpenedTabModel : public samsung_browser_fw_core::AccountModel {
+  friend class BPOpenedTabSigData;
+
+ public:
+  BPOpenedTabModel();
+  virtual ~BPOpenedTabModel();
+
+  bool init();
+  void deinit();
+
+  void tabInfoFree(bp_tab_info_fmt* info);
+  bool add(samsung_browser_fw_core::OpenedTabItem&);
+  bool remove(const samsung_browser_fw_core::OpenedTabItem&);
+  bool removeDevice(const std::string& device);
+  bool removeAll();
+  std::vector<samsung_browser_fw_core::OpenedTabItem> getOpenedTabs(
+      const std::string& device,
+      OpenedTabItemOrder,
+      int limit,
+      int offset);
+  samsung_browser_fw_core::OpenedTabItem getOpenedTab(
+      const samsung_browser_fw_core::OpenedTabID&);
+  std::vector<std::string> getDeviceList();
+  int count();
+
+  static std::string sourceName;
+  std::string getSourceName() const { return sourceName; }
+
+ private:
+  samsung_browser_fw_core::OpenedTabItem getOpenedTabItem(int cloud_id);
+
+  static void dataChangedCallback(void* data /*BPOpenedTabModel*/);
+  void dataChanged();
+  void initializeOpenedTabAdaptor();
+
+  TabIdStore m_idStore;
+  static bool m_initialized;
+  bool m_OpenedTabAdaptorInitialized;
+};
+
+}  // namespace samsung_browser_storage
+
+#endif  // COMPONENTS_SAMSUNG_OPENED_TABS_OPENED_TAB_MODEL_H_
diff --git a/components/samsung/opened_tabs/tab_id_store.h b/components/samsung/opened_tabs/tab_id_store.h
new file mode 100644 (file)
index 0000000..3a75d18
--- /dev/null
@@ -0,0 +1,200 @@
+#ifndef COMPONENTS_SAMSUNG_OPENED_TABS_TAB_ID_STORE_H_
+#define COMPONENTS_SAMSUNG_OPENED_TABS_TAB_ID_STORE_H_
+
+#include <functional>
+#include <set>
+
+#include "opened_tab_id.h"
+
+/*
+ * TabIdStore is a class designed to store and manage matching between
+ * cloud and browser bookmark id's. It allows to to add and remove
+ * matching between id's, and basing on one type id value get matched
+ * value of second one.
+ */
+class TabIdStore {
+  class IdMatch {
+    enum class StoreType { Both, OnlyBP, OnlyCloud };
+
+   public:
+    /*
+     * This constructor should be used for constructing class object to
+     * store in a set.
+     */
+    IdMatch(samsung_browser_fw_core::OpenedTabID bid, int cid)
+        : m_bid(bid), m_cid(cid), m_type(StoreType::Both) {}
+
+    /*
+     * This constructor should be used for constructing class object used
+     * to find in a set a cloud bookmark id matched to provided browser
+     * bookmark id
+     */
+    explicit IdMatch(samsung_browser_fw_core::OpenedTabID bid)
+        : m_bid(bid), m_cid(-1), m_type(StoreType::OnlyBP) {}
+
+    /*
+     * This constructor should be used for constructing class object used
+     * to find in a set a browser bookmark id matched to provided cloud
+     * bookmark id
+     */
+    explicit IdMatch(int cid)
+        : m_bid(samsung_browser_fw_core::OpenedTabID::NONE),
+          m_cid(cid),
+          m_type(StoreType::OnlyCloud) {}
+
+    samsung_browser_fw_core::OpenedTabID getOpenedTabId() const {
+      return m_bid;
+    }
+    int getcid() const { return m_cid; }
+
+    /*
+     * Operator check which id are stored in both object and basing on this
+     * information validate if they are equal. If one value is not set then
+     * it is assumed that it should not be took into account in comparison.
+     */
+    bool operator==(const IdMatch& b) const {
+      /*
+       * Validate case when object doesn't hold same type of id's and
+       * are not able to compare.
+       */
+      if ((m_type == StoreType::OnlyBP && b.m_type == StoreType::OnlyCloud) ||
+          (m_type == StoreType::OnlyCloud && b.m_type == StoreType::OnlyBP)) {
+        return false;
+      }
+
+      /*
+       * Validate situation when at least one object hold only browser
+       * type of bookmark id. In such case only m_bid is comparable.
+       */
+      if (m_type == StoreType::OnlyBP || b.m_type == StoreType::OnlyBP) {
+        return m_bid == b.m_bid;
+      }
+
+      /*
+       * Validate situation when at least one object hold only cloud
+       * type of bookmark id. In such case only m_cid is comparable.
+       */
+      if (m_type == StoreType::OnlyCloud || b.m_type == StoreType::OnlyCloud) {
+        return m_cid == b.m_cid;
+      }
+
+      /*
+       * Case which left is that both object hold both types of id.
+       */
+      return ((m_bid == b.m_bid) && m_cid == b.m_cid);
+    }
+
+    /*
+     * This operator is used by a container object to build a search tree
+     * and speed up searching mechanism. It is not possible to build a right
+     * tree which will be navigate-able for both types of id's. If one type
+     * of id will be sorted, most probable second type of id will not be
+     * sorted. Thats why this operator prefers a cloud bookmark id. Thanks
+     * that a set of IdMatch can use build in search mechanism to find an
+     * object basing on a cloud bookmark id.
+     */
+    bool operator<(const IdMatch& b) const {
+      // This case should not occurs. Such object are not comparable
+      if ((m_type == StoreType::OnlyBP && b.m_type == StoreType::OnlyCloud) ||
+          (m_type == StoreType::OnlyCloud && b.m_type == StoreType::OnlyBP)) {
+        return false;
+      }
+
+      /*
+       * Validate case when one object has only browser type of id.
+       */
+      if (m_type == StoreType::OnlyBP || b.m_type == StoreType::OnlyBP) {
+        return m_bid < b.m_bid;
+      }
+
+      return m_cid < b.m_cid;
+    }
+
+   private:
+    samsung_browser_fw_core::OpenedTabID m_bid;
+    int m_cid;
+    StoreType m_type;
+  };
+
+ public:
+  TabIdStore(){};
+
+  /*
+   * Add to base information about matching between provided id's.
+   */
+  void add(const samsung_browser_fw_core::OpenedTabID& bid, int cid) {
+    m_idSet.insert(IdMatch(bid, cid));
+  }
+
+  /*
+   * Returns a cloud bookamrk id matched to a provided browser one.
+   * If provided id cannot be found in data base then will be returned
+   * -1, which represents main folder or invalid id, depends on context.
+   */
+  int find(const samsung_browser_fw_core::OpenedTabID& bid) const {
+    if (bid == samsung_browser_fw_core::OpenedTabID::NONE) {
+      return -1;
+    }
+    /*
+     * Search tree in  data base is built basing on a cloud type of
+     * bookmark * id. Thats why 'find' provided by std::set will not work
+     * correctly and have to be used std::find.
+     */
+    auto it = std::find(m_idSet.begin(), m_idSet.end(), IdMatch(bid));
+    if (it != m_idSet.end()) {
+      return it->getcid();
+    }
+    return -1;
+  }
+
+  /*
+   * Returns a browser bookamrk id matched to a provided cloud one.
+   * If provided id cannot be found in data base then will be returned
+   * BookmarkID::NONE, which represents main folder or invalid id, depends
+   * on context.
+   */
+  samsung_browser_fw_core::OpenedTabID find(int cid) const {
+    if (cid == -1) {
+      return samsung_browser_fw_core::OpenedTabID::NONE;
+    }
+    /*
+     * Search tree in  data base is built basing on a cloud type of
+     * bookmark * id. Thats why 'find' provided by std::set can be used.
+     */
+    auto it = m_idSet.find(IdMatch(cid));
+    if (it != m_idSet.end()) {
+      return it->getOpenedTabId();
+    }
+    return samsung_browser_fw_core::OpenedTabID::NONE;
+  }
+
+  /*
+   * Clear whole data base.
+   */
+  void clear() { m_idSet.clear(); }
+
+  /*
+   * Remove from data base matching related to provided browser bookmark id.
+   */
+  void remove(const samsung_browser_fw_core::OpenedTabID& bid) {
+    auto it = std::find(m_idSet.begin(), m_idSet.end(), IdMatch(bid));
+    if (it != m_idSet.end()) {
+      m_idSet.erase(it);
+    }
+  }
+
+  /*
+   * Remove from data base matching related to provided cloud bookmark id.
+   */
+  void remove(int cid) {
+    auto it = m_idSet.find(IdMatch(cid));
+    if (it != m_idSet.end()) {
+      m_idSet.erase(it);
+    }
+  }
+
+ private:
+  std::set<IdMatch> m_idSet;
+};
+
+#endif  // COMPONENTS_SAMSUNG_OPENED_TABS_TAB_ID_STORE_H_
diff --git a/components/samsung/public/account_manager/samsung_image_tools_observer.h b/components/samsung/public/account_manager/samsung_image_tools_observer.h
new file mode 100644 (file)
index 0000000..6018578
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef COMPONENTS_SAMSUNG_PUBLIC_ACCOUNT_MANAGER_IMAGE_TOOLS_OBSERVER_H
+#define COMPONENTS_SAMSUNG_PUBLIC_ACCOUNT_MANAGER_IMAGE_TOOLS_OBSERVER_H
+
+#include "base/observer_list.h"
+
+namespace samsung_browser_storage {
+class ImageAddedObserver : public base::CheckedObserver {
+ public:
+  virtual void ImageAdded(const std::string& url,
+                          samsung_browser_fw_core::Image::ImageType type) {}
+};
+class ImageRemovedObserver : public base::CheckedObserver {
+ public:
+  virtual void ImagedRemoved(const std::string& url,
+                             samsung_browser_fw_core::Image::ImageType type) {}
+};
+class AllImagesRemovedObserver : public base::CheckedObserver {
+ public:
+  virtual void AllImagesRemoved(
+      samsung_browser_fw_core::Image::ImageType type) {}
+};
+}  // namespace samsung_browser_storage
+#endif
diff --git a/components/samsung/public/data_sync_service/data_sync_service.cc b/components/samsung/public/data_sync_service/data_sync_service.cc
new file mode 100644 (file)
index 0000000..59a08e1
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/samsung/public/data_sync_service/data_sync_service.h"
+
+#include "base/logging.h"  //For LOG Lines
+#include "components/samsung/data_sync_service/data_sync_service_impl.h"
+
+namespace samsung_browser_service {
+DataSyncService::DataSyncService() : m_initialized(false) {
+  LOG(INFO) << "DataSyncService Constructor Start!";
+}
+
+DataSyncService::~DataSyncService() {
+  DeInit();
+}
+
+bool DataSyncService::Init() {
+  LOG(INFO) << "DataSyncService::Init() start";
+  data_sync_service_impl = std::make_unique<DataSyncServiceImpl>();
+  LOG(INFO) << "DataSyncService::Init() done";
+  return data_sync_service_impl->Init();
+}
+
+bool DataSyncService::DeInit() {
+  LOG(INFO) << "DataSyncService DeInit called";
+  if (!m_initialized) {
+    LOG(ERROR) << "Already DeInitialized";
+    return false;
+  }
+  m_initialized = false;
+  return true;
+}
+
+void DataSyncService::connectToCloud() {
+  LOG(INFO) << "DataSyncService connectToCloud called";
+  data_sync_service_impl->connectToCloud();
+}
+
+void DataSyncService::disconnectToCloud() {
+  LOG(INFO) << "DataSyncService disconnectToCloud called";
+  data_sync_service_impl->disconnectToCloud();
+}
+
+void DataSyncService::changeAdaptersState(
+    samsung_browser_main::SynchronizationItem adapter,
+    bool enable) {
+  LOG(INFO) << "DataSyncService changeAdaptersState called";
+  data_sync_service_impl->changeAdaptersState(adapter, enable);
+}
+
+void DataSyncService::syncAdapter(
+    samsung_browser_main::SynchronizationItem adapter) {
+  LOG(INFO) << "DataSyncService syncAdapter called";
+  data_sync_service_impl->syncAdapter(adapter);
+}
+
+void DataSyncService::enableAdaptersAutoSync(
+    bool enable,
+    samsung_browser_main::SynchronizationItem item) {
+  LOG(INFO) << "DataSyncService enableAdapterAutoSync callled";
+  data_sync_service_impl->enableAdaptersAutoSync(enable, item);
+}
+}  // namespace samsung_browser_service
\ No newline at end of file
diff --git a/components/samsung/public/data_sync_service/data_sync_service.h b/components/samsung/public/data_sync_service/data_sync_service.h
new file mode 100644 (file)
index 0000000..e743ef3
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef COMPONENTS_SAMSUNG_PUBLIC_DATA_SYNC_SERVICE_DATA_SYNC_SERVICE_H_
+#define COMPONENTS_SAMSUNG_PUBLIC_DATA_SYNC_SERVICE_DATA_SYNC_SERVICE_H_
+
+#include "components/samsung/public/samsung_browser_enums.h"
+#include "ui/aura/window_tree_host_platform.h"
+
+namespace samsung_browser_service {
+
+class DataSyncServiceImpl;
+
+class DataSyncService {
+ public:
+  DataSyncService();
+  virtual ~DataSyncService();
+  bool Init();
+  bool DeInit();
+  void connectToCloud();
+  void disconnectToCloud();
+  void enableAdaptersAutoSync(
+      bool,
+      samsung_browser_main::SynchronizationItem item =
+          samsung_browser_main::SynchronizationItem::BookMarkTabAndWatchLater);
+
+ private:
+  void changeAdaptersState(samsung_browser_main::SynchronizationItem, bool);
+  void syncAdapter(samsung_browser_main::SynchronizationItem);
+  bool m_cloudInitialised;
+  bool m_isConnectionRequested;
+  bool m_syncEnable;
+  int m_timerCnt;
+  bool m_initialized;
+  std::unique_ptr<DataSyncServiceImpl> data_sync_service_impl;
+};
+}  // namespace samsung_browser_service
+
+#endif
\ No newline at end of file
index d6584e9825824177ebc5a926e955aa4e543390f6..bde9a38b88b8756b3b079047c75972039af86e54 100644 (file)
@@ -69,5 +69,15 @@ enum class NativePopupType {
   MENU_TREE = 3,
   CONTEXT_MENU = 4
 };
+enum SynchronizationItem {
+  Bookmarks = 0,
+  Tabs
+#ifdef ENABLE_WATCHLATER
+  ,
+  WatchLater
+#endif
+  ,
+  BookMarkTabAndWatchLater
+};
 }
 #endif  // COMPONENTS_SAMSUNG_SAMSUNG_BROWSER_ENUMS_H_
diff --git a/components/samsung/samsung_cloud/libsamsungcloud.so b/components/samsung/samsung_cloud/libsamsungcloud.so
new file mode 100644 (file)
index 0000000..5ffc0cc
Binary files /dev/null and b/components/samsung/samsung_cloud/libsamsungcloud.so differ
diff --git a/components/samsung/samsung_cloud/samsung_cloud.h b/components/samsung/samsung_cloud/samsung_cloud.h
new file mode 100644 (file)
index 0000000..1219d10
--- /dev/null
@@ -0,0 +1,31 @@
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * This software is the confidential and proprietary information of
+ * Samsung Electronics Co., Ltd. ("Confidential Information").
+ * You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement
+ * you entered into with Samsung Electronics Co., Ltd. ("SAMSUNG").
+ *
+ * SAMSUNG MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
+ * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+ * A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SAMSUNG SHALL NOT BE
+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
+ * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+ */
+
+#ifndef __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_H__
+#define __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_H__
+
+/**
+ * This header file is included to define _EXPORT_.
+ */
+
+#include "components/samsung/samsung_cloud/samsung_cloud_error.h"
+#include "components/samsung/samsung_cloud/samsung_cloud_service.h"
+
+#endif /* __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_H__ */
diff --git a/components/samsung/samsung_cloud/samsung_cloud_error.h b/components/samsung/samsung_cloud/samsung_cloud_error.h
new file mode 100644 (file)
index 0000000..14a025d
--- /dev/null
@@ -0,0 +1,77 @@
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * This software is the confidential and proprietary information of
+ * Samsung Electronics Co., Ltd. ("Confidential Information").
+ * You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement
+ * you entered into with Samsung Electronics Co., Ltd. ("SAMSUNG").
+ *
+ * SAMSUNG MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
+ * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+ * A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SAMSUNG SHALL NOT BE
+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
+ * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+ */
+
+#ifndef __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_ERROR_H__
+#define __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_ERROR_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_SAMSUNG_CLOUD_AGENT_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration of error code for Samsung Cloud.
+ * @since_ses 1
+ */
+typedef enum {
+  SAMSUNG_CLOUD_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+  SAMSUNG_CLOUD_ERROR_OUT_OF_MEMORY =
+      TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+  SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER =
+      TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+  SAMSUNG_CLOUD_ERROR_FILE_NO_SPACE =
+      TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
+  SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED =
+      TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+  SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED =
+      TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+  SAMSUNG_CLOUD_ERROR_CANCELED =
+      TIZEN_ERROR_CANCELED, /**< Operation Canceled */
+  SAMSUNG_CLOUD_ERROR_NO_DATA =
+      TIZEN_ERROR_NO_DATA, /**< Requested data does not exist */
+  SAMSUNG_CLOUD_ERROR_RESOURCE_BUSY =
+      TIZEN_ERROR_RESOURCE_BUSY, /**< Thread is busy */
+  SAMSUNG_CLOUD_ERROR_NETWORK_UNREACHABLE =
+      TIZEN_ERROR_NETWORK_UNREACHABLE,               /**< Network failed */
+  SAMSUNG_CLOUD_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown */
+  SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE =
+      TIZEN_ERROR_UNKNOWN - 6, /**< Service unavailable */
+  SAMSUNG_CLOUD_ERROR_LOWER_VERSION =
+      TIZEN_ERROR_UNKNOWN - 7, /**< Lower version */
+  SAMSUNG_CLOUD_ERROR_ACCOUNT_SESSION_EXPIRED =
+      TIZEN_ERROR_UNKNOWN -
+      8, /**< Samsung account session expired (Since API Level 4)*/
+} samsung_cloud_error_e;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_ERROR_H__ */
diff --git a/components/samsung/samsung_cloud/samsung_cloud_service.h b/components/samsung/samsung_cloud/samsung_cloud_service.h
new file mode 100644 (file)
index 0000000..35da89b
--- /dev/null
@@ -0,0 +1,839 @@
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * This software is the confidential and proprietary information of
+ * Samsung Electronics Co., Ltd. ("Confidential Information").
+ * You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement
+ * you entered into with Samsung Electronics Co., Ltd. ("SAMSUNG").
+ *
+ * SAMSUNG MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
+ * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
+ * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+ * A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SAMSUNG SHALL NOT BE
+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
+ * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
+ */
+
+#ifndef __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_SERVICE_H__
+#define __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_SERVICE_H__
+
+#include <tizen.h>
+#include "samsung_cloud_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_SAMSUNG_CLOUD_AGENT_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration of connection status.
+ * @since_ses 1
+ */
+typedef enum {
+  SAMSUNG_CLOUD_CONNECTION_STATUS_CONNECTED = 0, /**< Connected */
+  SAMSUNG_CLOUD_CONNECTION_STATUS_DISCONNECTED,  /**< Disconnected */
+  SAMSUNG_CLOUD_CONNECTION_STATUS_REJECTED,      /**< Rejected */
+} samsung_cloud_connection_status_e;
+
+/**
+ * @brief Enumeration of adapter.
+ * @since_ses 1
+ */
+typedef enum {
+  SAMSUNG_CLOUD_ADAPTER_ALL = -1,              /**< All adapters*/
+  SAMSUNG_CLOUD_ADAPTER_CALENDAR = 0,          /**< Calendar event */
+  SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK,      /**< Browser bookmark */
+  SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB,           /**< Browser tab */
+  SAMSUNG_CLOUD_ADAPTER_SAMSUNG_PASS,          /**< Samsung pass */
+  SAMSUNG_CLOUD_ADAPTER_KNOX_BROWSER_BOOKMARK, /**< Knox Browser bookmark (Since
+                                                  API level 8)*/
+  SAMSUNG_CLOUD_ADAPTER_KNOX_BROWSER_TAB, /**< Knox Browser tab (Since API level
+                                             8)*/
+  SAMSUNG_CLOUD_ADAPTER_KNOX_SAMSUNG_PASS, /**< Knox Samsung pass (Since API
+                                              level 8)*/
+  SAMSUNG_CLOUD_ADAPTER_REMOTE_ACCESS,     /**< Remote   Access (Since API level
+                                              8)*/
+  SAMSUNG_CLOUD_ADAPTER_WATCH_LATER, /**< Watch Later (Since API level 11)*/
+} samsung_cloud_adapter_e;
+
+/**
+ * @brief Enumeration of AES key.
+ * @since_ses 12
+ */
+typedef enum {
+  SAMSUNG_CLOUD_AES_KEY_128 = -1, /**< Use AES 128 bit key */
+  SAMSUNG_CLOUD_AES_KEY_256 = 0,  /**< Use AES 256 bit key */
+} samsung_cloud_aes_key_e;
+
+/**
+ *  @brief   Samsung cloud handle.
+ *  @since_ses 1
+ */
+typedef struct samsung_cloud_s* samsung_cloud_h;
+
+/**
+ * @brief The callback for notifying change in certificate.
+ * @since_ses 12
+ *
+ * @remarks The @a handle should not be released.
+ * @remarks The @a handle is the same object for which the callback was
+ * set/added.
+ * @remarks The @a handle will be released when samsung_cloud_disconnect() is
+ * called.
+ *
+ * @param[in] handle The Samsung cloud handle
+ * @param[in] user_data The user data passed from the callback registration
+ * function
+ *
+ * @see samsung_cloud_set_update_certificate_cb()
+ * @see samsung_cloud_unset_update_certificate_cb()
+ */
+typedef void (*samsung_cloud_update_certificate_cb)(samsung_cloud_h handle,
+                                                    void* user_data);
+
+/**
+ * @brief The device information handle to get device information list
+ * associated with same samsung account.
+ * @since_ses 12
+ * @see samsung_cloud_get_device_info_list()
+ * @see samsung_cloud_release_device_info_list()
+ */
+typedef struct samsung_cloud_device_info_s* samsung_cloud_device_info_h;
+
+/**
+ * @brief Called when the connection status is changed.
+ * @details The following error codes can be received: \n
+        #SAMSUNG_CLOUD_ERROR_NONE:                    Success \n
+        #SAMSUNG_CLOUD_ERROR_UNKNOWN:                 Unknown \n
+        #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE:     Service unavailable \n
+        #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED:           Not supported \n
+ * @since_ses 1
+ * @param[in] result The result code
+ * @param[in] status The connection status
+ * @param[in] user_data The user data passed from the callback function
+ * @see samsung_cloud_connect()
+ */
+typedef void (*samsung_cloud_connection_status_changed_cb)(
+    samsung_cloud_error_e result,
+    samsung_cloud_connection_status_e status,
+    void* user_data);
+
+/**
+ * @brief Callback for getting the get or set result of the request.
+ * @details The following error codes can be received: \n
+        #SAMSUNG_CLOUD_ERROR_NONE:                    Success \n
+        #SAMSUNG_CLOUD_ERROR_OUT_OF_MEMORY:           Out of memory \n
+        #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER:       Invalid parameter \n
+        #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED:           Not supported \n
+        #SAMSUNG_CLOUD_ERROR_UNKNOWN:                 Unknown \n
+        #SAMSUNG_CLOUD_ERROR_RESOURCE_BUSY:           Thread is busy \n
+        #SAMSUNG_CLOUD_ERROR_NETWORK_UNREACHABLE:     Network failed \n
+        #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE:     Service unavailable \n
+ * @since_ses 1
+ * @param[in] result The result code
+ * @param[in] user_data The user data passed from the callback function
+ */
+typedef void (*samsung_cloud_result_cb)(int result, void* user_data);
+
+/**
+ * @brief Connects to the Samsung Cloud Agent.
+ * @since_ses 1
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/datasharing \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a handle will be released when application is disconnected
+ * using samsung_cloud_disconnect().
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data passed from the callback functions
+ * @param[out] handle The service handle
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_disconnect()
+ */
+int samsung_cloud_connect(samsung_cloud_connection_status_changed_cb callback,
+                          void* user_data,
+                          samsung_cloud_h* handle);
+
+/**
+ * @brief Disconnects from the Samsung Cloud Agent.
+ * @since_ses 1
+ * @param[in] handle The service handle
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see samsung_cloud_connect()
+ */
+int samsung_cloud_disconnect(samsung_cloud_h handle);
+
+/**
+ * @brief Starts adapter sync.
+ * @since_ses 1
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a callback will be called after sync is done. \n
+ *          If #SAMSUNG_CLOUD_ADAPTER_ALL is used as adapter parameter,
+ *          all adapters(#SAMSUNG_CLOUD_ADAPTER_CALENDAR,
+ * #SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK, and so on) syncing will be triggered
+ * to start sync. \n Required privileges are different depending on
+ * #samsung_cloud_adapter_e.\n #SAMSUNG_CLOUD_ADAPTER_CALENDAR needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push,
+ * http://tizen.org/privilege/calendar.read,
+ *          http://tizen.org/privilege/calendar.write.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_SAMSUNG_PASS needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.
+ * @param[in] handle    The cloud handle
+ * @param[in] adapter   The adapter
+ * @param[in] login_id  The login ID
+ * @param[in] callback  The callback function to invoke
+ * @param[in] user_data The user data passed from the callback functions
+ * @return @c 0 on success.
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ * @retval #SAMSUNG_CLOUD_ERROR_ACCOUNT_SESSION_EXPIRED Samsung account session
+ * expired(Since API Level 4)
+ *
+ * @see samsung_cloud_cancel_sync()
+ */
+int samsung_cloud_start_sync(samsung_cloud_h handle,
+                             samsung_cloud_adapter_e adapter,
+                             const char* login_id,
+                             samsung_cloud_result_cb callback,
+                             void* user_data);
+
+/**
+ * @brief Cancels adapter sync.
+ * @since_ses 1
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a callback will be called after cancel is done.\n
+ *          If #SAMSUNG_CLOUD_ADAPTER_ALL is used as adapter parameter,
+ *          all adapters(#SAMSUNG_CLOUD_ADAPTER_CALENDAR,
+ * #SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK, and so on) syncing will be
+ * cancelled.\n Required privileges are different depending on
+ * #samsung_cloud_adapter_e.\n #SAMSUNG_CLOUD_ADAPTER_CALENDAR needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push,
+ * http://tizen.org/privilege/calendar.read,
+ *          http://tizen.org/privilege/calendar.write.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_SAMSUNG_PASS needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.
+ * @param[in] handle    The cloud handle
+ * @param[in] adapter   The adapter
+ * @param[in] callback  The callback function to invoke
+ * @param[in] user_data The user data passed from the callback functions
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_start_sync()
+ */
+int samsung_cloud_cancel_sync(samsung_cloud_h handle,
+                              samsung_cloud_adapter_e adapter,
+                              samsung_cloud_result_cb callback,
+                              void* user_data);
+
+/**
+ * @brief Sets adapter enable to sync or not.
+ * @since_ses 1
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks Required privileges are different depending on
+ * #samsung_cloud_adapter_e.\n #SAMSUNG_CLOUD_ADAPTER_CALENDAR needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push,
+ * http://tizen.org/privilege/calendar.read,
+ *          http://tizen.org/privilege/calendar.write.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_SAMSUNG_PASS needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.
+ * @param[in] handle    The cloud handle
+ * @param[in] adapter   The adapter
+ * @param[in] enable    The flag of enable on/off
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_adapter_enable()
+ */
+int samsung_cloud_set_adapter_enable(samsung_cloud_h handle,
+                                     samsung_cloud_adapter_e adapter,
+                                     bool enable);
+
+/**
+ * @brief Checks adapter enable whether value is set or not.
+ * @since_ses 1
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks Required privileges are different depending on
+ * #samsung_cloud_adapter_e.\n #SAMSUNG_CLOUD_ADAPTER_CALENDAR needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push,
+ * http://tizen.org/privilege/calendar.read,
+ *          http://tizen.org/privilege/calendar.write.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_BOOKMARK needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_BROWSER_TAB needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.\n
+ *          #SAMSUNG_CLOUD_ADAPTER_SAMSUNG_PASS needs
+ * http://tizen.org/privilege/network.get, http://tizen.org/privilege/internet,
+ * http://tizen.org/privilege/account.read, http://tizen.org/privilege/push.
+ * @param[in] handle    The cloud handle
+ * @param[in] adapter   The adapter
+ * @param[out] is_enabled On/Off flag check if adapter is enabled or not
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_set_adapter_enable()
+ */
+int samsung_cloud_get_adapter_enable(samsung_cloud_h handle,
+                                     samsung_cloud_adapter_e adapter,
+                                     bool* is_enabled);
+
+/**
+ * @brief Gets device info list.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a device_info_list_h should be released using
+ * samsung_cloud_release_device_info_list()
+ * @param[in] handle    The cloud handle
+ * @param[out] device_info_list_h    device info list
+ * @param[out] list_size    Number of devices in the device info list
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_release_device_info_list()
+ */
+int samsung_cloud_get_device_info_list(
+    samsung_cloud_h handle,
+    samsung_cloud_device_info_h** device_info_list_h,
+    int* list_size);
+
+/**
+ * @brief Gets device ID from device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a device_id should be released using free
+ * @param[in] device_info_h    The device info handle
+ * @param[out] device_id    device id
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+
+int samsung_cloud_device_info_get_id(samsung_cloud_device_info_h device_info_h,
+                                     char** device_id);
+
+/**
+ * @brief Gets device name from device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a device_name should be released using free
+ * @param[in] device_info_h    The device info handle
+ * @param[out] device_name    device name
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+
+int samsung_cloud_device_info_get_name(
+    samsung_cloud_device_info_h device_info_h,
+    char** device_name);
+
+/**
+ * @brief Gets device model from device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a device_model should be released using free
+ * @param[in] device_info_h    The device info handle
+ * @param[out] device_model    device model
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+
+int samsung_cloud_device_info_get_model(
+    samsung_cloud_device_info_h device_info_h,
+    char** device_model);
+
+/**
+ * @brief Gets device type from device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a device_type should be released using free
+ * @param[in] device_info_h    The device info handle
+ * @param[out] device_type    device type
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+
+int samsung_cloud_device_info_get_type(
+    samsung_cloud_device_info_h device_info_h,
+    char** device_type);
+
+/**
+ * @brief Gets device's bluetooth address from device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a bt_addr should be released using free
+ * @remarks The @a bt_addr could be NULL if device don't have bluetooth
+ * @param[in] device_info_h  The device info handle
+ * @param[out] bt_addr       bluetooth address
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+int samsung_cloud_device_info_get_bt_addr(
+    samsung_cloud_device_info_h device_info_h,
+    char** bt_addr);
+
+/**
+ * @brief Gets device's WiFi address form device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a wifi_addr should be released using free
+ * @remarks The @a wifi_addr could be NULL
+ * @param[in] device_info_h    The device info handle
+ * @param[out] wifi_addr    WiFi adapter MAC address
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+
+int samsung_cloud_device_info_get_wifi_addr(
+    samsung_cloud_device_info_h device_info_h,
+    char** wifi_addr);
+
+/**
+ * @brief Gets device Bluetooth's identity resolving key from device info.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/calendar.write \n
+ *            %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/calendar.read \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks The @a irk should be released using free
+ * @param[in] device_info_h    The device info handle
+ * @param[out] irk    BT IRK (identity resolving key)
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+
+int samsung_cloud_device_info_get_irk(samsung_cloud_device_info_h device_info_h,
+                                      char** irk);
+/**
+ * @brief Releases memory allocated in samsung_cloud_get_device_info_list().
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @param[in] device_info_list_h    list of device info handles
+ * @param[in] list_size             Number of devices in the device info list
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info_list()
+ */
+int samsung_cloud_release_device_info_list(
+    samsung_cloud_device_info_h* device_info_list_h,
+    int list_size);
+
+/**
+ * @brief Provides fingerprint to the user.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @details Certificate generation is done by calling
+ * samsung_cloud_get_fingerprint() internally.Generate certifciate is a REST API
+ * which cloud agent request to cloud server.It includes a few processes like
+ * create csr, create key pair and signin csr , etc .. Cloud server sends back
+ * 'userFingerprint' as one of its response values and cloud agent saves it and
+ * delivers when any application or service requests by calling
+ * samsung_cloud_get_fingerprint().
+ * @remarks Release fingerprint using free() after use.
+ * @param[in] handle    The cloud handle
+ * @param[out] fingerprint Contains fingerprint requested by user
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_device_info()
+ * @see samsung_cloud_get_encrypted_buffer()
+ * @see samsung_cloud_get_decrypted_buffer()
+ */
+int samsung_cloud_get_fingerprint(samsung_cloud_h handle, char** fingerprint);
+
+/**
+ * @brief Encrypts data provided by user.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks Decrypt using samsung_cloud_get_decrypted_buffer(),any device with
+ * same user logged in can decrypt.
+ * @remarks The @a out_buffer should be released using free()
+ * @param[in] handle    The cloud handle
+ * @param[in] in_buffer    Text or buffer to encrypt
+ * @param[in] in_size    Size of buffer to encrypt
+ * @param[in] iv    Initialization vector used to encrypt buffer (Size must be
+ * of 128 bits)
+ * @param[in] key_bit    Key to be used for encryption (128 or 256 bit)
+ * @param[out] out_buffer Encrypted buffer
+ * @param[out] out_size Size of encrypted buffer
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_decrypted_buffer()
+ */
+int samsung_cloud_get_encrypted_buffer(samsung_cloud_h handle,
+                                       const char* in_buffer,
+                                       int in_size,
+                                       unsigned char* iv,
+                                       samsung_cloud_aes_key_e key_bit,
+                                       char** out_buffer,
+                                       int* out_size);
+
+/**
+ * @brief Decrypts the encrypted buffer provided by user.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks iv and key_bit must be same as used to encrypt
+ * @remarks any device with same user logged in can decrypt .
+ * @remarks The @a out_buffer should be released using free()
+ * @param[in] handle    The cloud handle
+ * @param[in] in_buffer    Buffer to decrypt
+ * @param[in] in_size    Size of buffer to decrypt
+ * @param[in] iv    Initialization vector used to encrypt buffer (Size must be
+ * of 128 bits). Must be same as used for encryption
+ * @param[in] key_bit    Key to be used for decryption (128 or 256 bit). Must be
+ * same as used for encryption
+ * @param[out] out_buffer Decrypted text or buffer
+ * @param[out] out_size Size of decrypted text or buffer
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_get_encrypted_buffer()
+ */
+int samsung_cloud_get_decrypted_buffer(samsung_cloud_h handle,
+                                       const char* in_buffer,
+                                       int in_size,
+                                       unsigned char* iv,
+                                       samsung_cloud_aes_key_e key_bit,
+                                       char** out_buffer,
+                                       int* out_size);
+
+/**
+ * @brief Sets callback notification for certificate update.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @remarks Unset callback when notification is no longer required.
+ * @param[in] handle     The cloud handle
+ * @param[in] callback   The callback function to invoke
+ * @param[in] user_data  The user data passed from the callback functions
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_unset_update_certificate_cb()
+ */
+int samsung_cloud_set_update_certificate_cb(
+    samsung_cloud_h handle,
+    samsung_cloud_update_certificate_cb callback,
+    void* user_data);
+
+/**
+ * @brief Unsets callback notification for update certificate.
+ * @since_ses 12
+ * @privilege %http://tizen.org/privilege/network.get \n
+ *            %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/push \n
+ *            %http://tizen.org/privilege/account.read \n
+ *            %http://tizen.org/privilege/internet \n
+ *            %http://tizen.org/privilege/datasharing \n
+ *            %http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud
+ * @param[in] handle     The cloud handle
+ * @param[in] user_data  The user data passed from the callback functions
+ * @return @c 0 on success
+ *         otherwise a negative error value
+ * @retval #SAMSUNG_CLOUD_ERROR_NONE Successful
+ * @retval #SAMSUNG_CLOUD_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SAMSUNG_CLOUD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SAMSUNG_CLOUD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SAMSUNG_CLOUD_ERROR_SERVICE_UNAVAILABLE Service unavailable
+ * @retval #SAMSUNG_CLOUD_ERROR_UNKNOWN Unknown
+ *
+ * @see samsung_cloud_set_update_certificate_cb()
+ */
+int samsung_cloud_unset_update_certificate_cb(samsung_cloud_h handle,
+                                              void* user_data);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SAMSUNG_EXPERIENCE_SERVICE_SAMSUNG_CLOUD_SERVICE_H__ */
index 6788d5129c77d49b620f63f674d6209b4cf79ad6..2e71a077c43f0561575fa5685d3a95362f286d88 100644 (file)
@@ -241,12 +241,14 @@ BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(zlib)
 %if 0%{?__build_next_browser}
 #Added below pkg for Next Browser
+BuildRequires: dapi-provider-devel
 BuildRequires: pkgconfig(vd-elementary)
 BuildRequires: pkgconfig(efl-assist)
 BuildRequires: pkgconfig(uifw_misc)
 BuildRequires: pkgconfig(was_db_api)
 BuildRequires: pkgconfig(capi-window-tv)
 BuildRequires: pkgconfig(VDCurl)
+BuildRequires: pkgconfig(capi-media-image-util)
 %endif
 
 # Applied python acceleration for generating gyp files.
index c20846335a0e8e39d92d793015301d380f27fc4d..0447b17ecb2b5b4a5f696057d7f69984b1c04839 100644 (file)
@@ -33,6 +33,9 @@
         <privilege>http://tizen.org/privilege/telephony</privilege>
         <privilege>http://tizen.org/privilege/telephony.admin</privilege>
         <privilege>http://tizen.org/privilege/tv.inputdevice</privilege>
+        <privilege>http://tizen.org/privilege/account.read</privilege>
+        <privilege>http://developer.samsung.com/privilege/sso.platform</privilege>
+        <appdefined-privilege>http://com.samsung.tizen.samsung-cloud/appdefined/samsung-cloud</appdefined-privilege>
     </privileges>
     <feature name="http://tizen.org/feature/screen.size.normal.1080.1920">true</feature>
 </manifest>
index 5112ea946cbca66b2613c685f54c9178feb1c2c9..817166d5cd3f9fc74989256ed6113a741edab735 100644 (file)
@@ -1042,8 +1042,24 @@ if (is_samsung_next_browser) {
   tizen_pkg_config("libsso_api") {
     packages = [ "sso_api" ]
   }
-}
 
+  config("capi-media-image-util") {
+    ldflags = [ "lcapi-media-image-util" ]
+  }
+
+  tizen_pkg_config("libcapi-media-image-util") {
+    packages = [ "capi-media-image-util" ]
+  }
+
+  config("capi-cloud-tab") {
+    ldflags = [ "-lcapi-cloud-tab" ]
+    cflags = [ "-dapi-provider" ]
+  }
+
+  tizen_pkg_config("libcapi-cloud-tab") {
+    packages = [ "capi-cloud-tab" ]
+  }
+}
 #Next browser package ends
 
 tizen_pkg_config("WebProduct") {
index e6c60c49e9fbebcaa9b5813d76f3a0f4283df343..0ba21cdee15349de1ee4f4060fcbb8d6653f596a 100755 (executable)
@@ -63,6 +63,8 @@ install -m 0644 ${output_dir}/resources/*.edj ${tpk_root}/res/themes
 
 install -m 0755 ${ro_lib_root}/lib/libchromium-impl.so ${tpk_root}/lib
 install -m 0755 ${output_dir}/libchromium-ewk.so ${tpk_root}/lib
+install -m 0755 ./components/samsung/samsung_cloud/libsamsungcloud.so ${tpk_root}/lib
+
 #install -m 0644 ${ro_lib_root}/../../../NextBrowser/chromium-efl.img ${tpk_root}/res/
 
 # Test signing
index 57b151a7f5726dc1109ddbba6b3ffe3516aebb06..1848b350a667d37e16ada49134b91929bbbb8699 100644 (file)
@@ -155,6 +155,10 @@ shared_library("chromium-ewk") {
     "-w",
   ]
 
+  if(is_samsung_next_browser) {
+  ldflags += [ "-Wl,-rpath=\$ORIGIN/../lib" ]
+  }
+
   if (is_tizen) {
     exclude_source_set = [
       "browser/sound_effect.cc",